网络编程——subprocess模块

import subprocess  

在代码中去调用操作系统的命令

r = subprocess.Popen('ls', shell= True,

stdout = subprocess.PIPE,

stderr = subprocess.PIPE)

#subprocess.Popen(cmd, shell = True, subprocess.stdout,subprocess.stderr)

# cmd :代表系统命令

# shell = True 代表这条命令是 系统命令,告诉操作系统,将cmd当初系统命令去执行

# stdout 是执行完系统命令之后,用于保存结果的一个管道

# stderr 是执行完系统命令之后, 用于保存错误结果的一个管道 

print(r.stdout.read().decode('gbk'))
print(r.stderr.read().decode('gbk'))

 

原文地址:https://www.cnblogs.com/Loren2o/p/9475118.html