I read this somewhere a while ago but cant seem to find it. I am trying to find a command that will execute commands in the terminal and then output the result.
For
In fact any question on subprocess will be a good read
You could import the 'os' module and use it like this :
import os
os.system('#DesiredAction')
I prefer usage of subprocess module:
from subprocess import call
call(["ls", "-l"])
Reason is that if you want to pass some variable in the script this gives very easy way for example take the following part of the code
abc = a.c
call(["vim", abc])
The os.popen() is pretty simply to use, but it has been deprecated since Python 2.6. You should use the subprocess module instead.
Read here: reading a os.popen(command) into a string
for python3 use subprocess
import subprocess
s = subprocess.getstatusoutput(f'ps -ef | grep python3')
print(s)
import os
os.system("echo 'hello world'")
This should work. I do not know how to print the output into the python Shell.