如通过为stdin, stdout和stderr传递不同的参数。...在python3中结果为byte类型,要得到str类型需要decode转换一下
输出结果(读)
# 直接执行命令输出到屏幕
>>> subprocess.Popen("ls -l",shell=True...的终端,执行一个print命令
proc = subprocess.Popen(['python3'],stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr...捕获错误输出
proc = subprocess.Popen(['python3'],stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE...进行交互并获取输出(stdout),这样能保证子进程正常退出而避免出现僵尸进程:
示例:
proc = subprocess.Popen('ls -l', shell=True, stdout=subprocess.PIPE