【发布时间】:2011-05-20 19:27:51
【问题描述】:
警告:Python 新手。
想听听实际使用它的专业人士的意见:
subprocess.Popen() 和 subprocess.call() 之间的主要区别是什么?什么时候最好使用它们?
除非您想了解我为什么要考虑这个问题,或者您的答案要围绕什么中心,否则您现在可以停止阅读。
我之所以提出这个问题是因为我正在解决一个脚本中的问题,我开始使用subprocess.Popen(),最终称为系统暂停,然后想删除造成系统暂停的 .exe,但我注意到Popen(),所有命令似乎都一起运行(.exe 上的删除在 exe 关闭之前执行..),尽管我尝试添加communicate()。
这是我上面描述的假代码:
subprocess.Popen(r'type pause.exe > c:\worker.exe', shell=True).communicate()
subprocess.Popen(r'c:\worker.exe', shell=True).communicate()
subprocess.Popen(r'del c:\worker.exe', shell=True).communicate()
【问题讨论】:
标签: python call subprocess popen