subprocess.Popen 和 os.system 的区别 [英] Difference between subprocess.Popen and os.system

查看:77
本文介绍了subprocess.Popen 和 os.system 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

subprocess.Popen()os.system() 有什么区别?

推荐答案

如果您查看 Python 文档的 subprocess 部分,您会注意到有一个示例说明如何将 os.system() 替换为 subprocess.Popen():

If you check out the subprocess section of the Python docs, you'll notice there is an example of how to replace os.system() with subprocess.Popen():

sts = os.system("mycmd" + " myarg")

...和...做同样的事情

...does the same thing as...

sts = Popen("mycmd" + " myarg", shell=True).wait()

改进"的代码看起来更复杂,但它更好,因为一旦你知道subprocess.Popen(),你就不需要其他任何东西了.subprocess.Popen() 替换了分散在其他三个 Python 模块中的其他几个工具(os.system() 只是其中之一).

The "improved" code looks more complicated, but it's better because once you know subprocess.Popen(), you don't need anything else. subprocess.Popen() replaces several other tools (os.system() is just one of those) that were scattered throughout three other Python modules.

如果有帮助,请将 subprocess.Popen() 视为非常灵活的 os.system().

If it helps, think of subprocess.Popen() as a very flexible os.system().

这篇关于subprocess.Popen 和 os.system 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆