So i have been messing about on my MacOS trying to run a Terminal command from within a Python File. Below is the code which i have been using so far:
#!/usr/bin/env python3
import os
import subprocess
print("IP Configuration for Machine")
cmd = ['ifconfig']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
o, e = proc.communicate()
print('OUTPUT: ' + o.decode('ascii'))
print('ERROR: ' + e.decode('ascii'))
print('CODE: ' + str(proc.returncode))
It works perfectly fine for when i intend to run only one Terminal Command. Right now i intend to run more than one, but so far it has been giving me errors. An example of my attempt:
print("IP Configuration for Machine & List Directory")
cmd = ['ifconfig', 'ls']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
I am wondering if there is a solution to my predicament