建立于: 6年前 ( 更新: 6年前 )
最简化版本的Python系统命令运行范本
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE, STDOUT
#运行的命令
command='ls -l'.split()
proc=Popen(command , stdout=PIPE,stderr=PIPE, universal_newlines=True);
output, error = proc.communicate()
#显示运行结果
if(proc.poll()==0):
print(output)
else:
print("{} Error\n".format(error))
No Comment
Post your comment