>>> import os
>>> output = os.system('cat /proc/cpuinfo')
processor : 0
vendor_id : AuthenticAMD
cpu family : 21
... ...
>>> output # doesn't capture output
0 >>> output = os.popen('cat /proc/cpuinfo')
>>> output
<open file 'cat /proc/cpuinfo', mode 'r' at 0x7ff52d831540>
>>> print output.read()
processor : 0
vendor_id : AuthenticAMD
cpu family : 21
... ...
>>><span style="font-size:14px;"> >>> import commands
>>> (status, output) = commands.getstatusoutput('cat /proc/cpuinfo')
>>> print output
processor : 0
vendor_id : AuthenticAMD
cpu family : 21
... ...
>>> print status
0 >>> import subprocess >>> subprocess.Popen(["ls", "-l"]) <strong> # python2.x</strong> doesn't capture output >>> subprocess.run(["ls", "-l"]) <strong># python3.x</strong> doesn't capture output <subprocess.Popen object at 0x7ff52d7ee490> >>> total 68 drwxrwxr-x 3 xl xl 4096 Feb 8 05:00 com drwxr-xr-x 2 xl xl 4096 Jan 21 02:58 Desktop drwxr-xr-x 2 xl xl 4096 Jan 21 02:58 Documents drwxr-xr-x 2 xl xl 4096 Jan 21 07:44 Downloads ... ... >>>
以上就是详解在Python中执行系统命令的方法的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于详解在Python中执行系统命令的方法的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did84417