Python Program Correction
<p>I need help I am trying to open the terminal and type ifconfig and enter then read the output on a mac then il transition this later to kali but I am getting a error with the file path to terminal and I cant start it, here is my code. </p>

<pre><code>import os,sys

#opens terminal

terminal = os.open('/Applications/Utilities/Terminal.app', os.O_RDWR|os.O_APPEND)

#writes ifconfig

os.write(terminal, 'ifconfig')

os.close(terminal)
</code></pre>

<p>I agree with using <a href="https://docs.python.org/3/library/subprocess.html#subprocess.check_output" rel="nofollow">subprocess</a>. To add to Amin's answer, for something this simple that you just want the output from:</p>

<pre><code>import subprocess

print(subprocess.check_output(['ifconfig']))
</code></pre>

<p>Edit: </p>

<p>What I was talking about in my comment is the new <a href="https://docs.python.org/3/library/subprocess.html#subprocess.run" rel="nofollow">run</a> function that returns a <a href="https://docs.python.org/3/library/subprocess.html#subprocess.CompletedProcess" rel="nofollow">CompletedProcess</a> class that holds all the relevant information for you. That way you no longer have to have three different variables holding your stdout, sterr and returncode.</p>

python osx terminal filepath