开发者

what is the system function in python

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 func开发者_JS百科tion in python ? Thanks in Advance .


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'


import os
os.system("")

From here


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜