[英]using subprocess pipe and stderr for one command
Basically, I am trying to run the command (in linux) 基本上,我试图运行命令(在Linux中)
chrome http://www.google.com | cleanup.py
and trying to log stderr to a file. 并尝试将stderr记录到文件中。
with open("/tmp/chrome-logs.txt", 'a') as tempf:
run_pipe = subprocess.Popen( ["-c", "cleanup.py"] , stdin=subprocess.PIPE, stderr=tempf, shell=True)
run_pipe.communicate("chrome","http://www.google.com")
How do I get this to work? 我如何让它工作?
I could however use subprocess.call to execute, but is that the best way? 但是我可以使用subprocess.call来执行,但这是最好的方法吗?
Try 尝试
stderr=open(<file name>', 'w')
And then you do not need communicate , you may also just use call instead of Popen 然后你不需要沟通 ,也可以只使用呼叫代替Popen
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.