subprocess.Popen()
和os.system()
有什么区别?
最佳答案
如果您查看 subprocess section of the Python docs ,您会注意到有一个示例说明如何将 os.system()
替换为 subprocess.Popen()
:
sts = os.system("mycmd" + " myarg")
...和...做同样的事情
sts = Popen("mycmd" + " myarg", shell=True).wait()
“改进”的代码看起来更复杂,但更好,因为一旦你知道了 subprocess.Popen()
,你就不需要其他任何东西了。 subprocess.Popen()
替换了分散在其他三个 Python 模块中的其他几个工具(os.system()
只是其中之一)。
如果有帮助,请将 subprocess.Popen()
视为一个非常灵活的 os.system()
。
关于python - subprocess.Popen 和 os.system 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4813238/