猿问

subprocess.Popen和os.system之间的区别

subprocess.Popen和os.system之间的区别

subprocess.Popen()和之间有什么区别os.system()



函数式编程
浏览 3044回答 3
3回答

幕布斯6054654

如果检查出Python文档的子部分,你会发现有一个如何来代替的例子os.system()有subprocess.Popen():sts = os.system("mycmd" + " myarg")......做同样的事......sts = Popen("mycmd" + " myarg", shell=True).wait()“改进的”代码看起来更复杂,但它更好,因为一旦你知道subprocess.Popen(),你不需要任何其他东西。subprocess.Popen()替换了os.system()分散在其他三个Python模块中的其他几个工具(只是其中之一)。如果有帮助,可以认为subprocess.Popen()是非常灵活的os.system()。

凤凰求蛊

subprocess.Popen()严格超集os.system()。

HUH函数

os.system等同于Unix 系统命令,而subprocess是一个辅助模块,用于提供Popen 命令提供的许多功能,并提供更简单,可控的接口。这些设计类似于Unix Popen命令。system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed在哪里The popen() function opens a process by creating a pipe, forking, and invoking the shell.如果您正在考虑使用哪一个,那么请务必使用子进程,因为您拥有所有执行工具,并且可以对该进程进行额外控制。
随时随地看视频慕课网APP

相关分类

Python
我要回答