I want to play with system command in python . for example we have this function in perl : system("ls -la"); and its run ls -la what is the system function in python ? Thanks in Advance .
+4
A:
It is os.system
:
import os
os.system('ls -la')
But this won't give you any output. So subprocess.check_output
is probably more what you want:
>>> import subprocess
>>> subprocess.check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
Felix Kling
2010-07-06 15:58:48
+1
A:
In the os
module there is os.system()
.
But if you want to do more advanced things with subprocesses the subprocess
module provides a higher level interface with more possibilities that is usually preferable.
sth
2010-07-06 16:01:46