I want to execute shell commands(Let say ubuntu's ls -a
command)
Now, after reading few SOF threads, I've found that the subprocess
module is best. Is that really the case?
from subprocess import call
t = call(['ls', '-a'])
print t
When I run this script it simply printed the result on my system's terminal, and the variable t
got the value 0
.
shell=False
is also not working; I just gave it a try.
How could I store result in a variable instead of printing it to the terminal (or may be to the terminal as well, if it is not possible to get rid of this)?
Can we use any other library for this purpose?
EDIT:
t = os.popen('ls -a').read()
This is working! But is there any bug, or some issue with this?