python执行shell命令
作者:互联网
import subprocess
def cmd(command):
subp = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
return subp.communicate()
res = cmd("ls -l")
res = res[0]
res = res.split("\n")
for line in res:
print(line)
搜索
复制
标签:shell,subp,python,res,subprocess,PIPE,命令,line 来源: https://www.cnblogs.com/kala/p/16418109.html