Python 为一个命令使用子流程管道和stderr

Python 为一个命令使用子流程管道和stderr,python,Python,基本上,我正在尝试运行该命令(在linux中) 并尝试将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

基本上,我正在尝试运行该命令(在linux中)

并尝试将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")
我怎样才能让它工作

不过,我可以使用subprocess.call来执行,但这是最好的方法吗?

试试看

stderr=open(<file name>', 'w')
stderr=open(','w')
然后你不需要交流,你也可以用call代替Popen

stderr=open(<file name>', 'w')