python子进程如何将stderr和stdout管道化到第二个进程stdin的stdin
我正在使用子进程运行命令,这些命令涉及将stderr和stdout管道传输到另一个程序,形式为python子进程如何将stderr和stdout管道化到第二个进程stdin的stdin,python,subprocess,Python,Subprocess,我正在使用子进程运行命令,这些命令涉及将stderr和stdout管道传输到另一个程序,形式为command1 2>&1 | command 2。 下面是一个玩具的例子 玩具命令1: sleep 2 echo "this is not an error!" sleep 2 (>&2 echo "THIS IS AN ERROR") 使用shell=True: run_string = 'bash dummy.sh 2>&1 | tee dummy.log' ps =
command1 2>&1 | command 2
。
下面是一个玩具的例子
玩具命令1
:
sleep 2
echo "this is not an error!"
sleep 2
(>&2 echo "THIS IS AN ERROR")
使用shell=True
:
run_string = 'bash dummy.sh 2>&1 | tee dummy.log'
ps = subprocess.Popen(run_string, shell=True)
我想删除shell=True
,因此无法使用|
我现在的位置:
ps = subprocess.Popen(['bash', 'dummy.sh'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = subprocess.check_output(('tee', 'dummy.log'), stdin=ps.stderr)
#I want stdin to be both stdout and stderr.
我想通过管道将两个stdout+stderr传输到具有子进程的第二个程序,shell=False
。
如何实现这一点?使用
stderr=subprocess.STDOUT
.Duh。非常感谢。如果你想要一些免费积分,你可以回答,我会接受。使用stderr=subprocess.STDOUT
.Duh。非常感谢。如果你想要一些免费积分,你可以回答,我会接受的。