子流程模块中的 check_call check_output 调用和 Popen 方法之间的实际区别是什么? [英] What is a practical difference between check_call check_output call, and Popen methods in the subprocess module?

查看:97
本文介绍了子流程模块中的 check_call check_output 调用和 Popen 方法之间的实际区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老实说,我只是不明白非零"状态的行话来真正解释帮助页面上正在发生的事情或这意味着什么(甚至没有定义).有哪些使用python调用其他脚本的例子,其中

Honestly, I just don't understand the lingo of "non-zero" status to really interpret what's going on or what that means (it wasn't even defined) on help pages. What are some examples of using python to call other scripts in which these processes of

subprocess.callsubprocess.check_outputsubprocess.popen

真的不一样吗?你什么时候会使用其中的任何一个,这些方法的明确细节是什么?如果我想要简单的操作系统调用,我应该使用 os.system 吗?

really differ from each other? When would you use either of those, and what are the disambiguated details of these methods? Should I be using os.system instead if I wanted simple OS calls?

推荐答案

主要区别在于,popen 是一个非阻塞函数(意味着你可以继续执行程序而无需等待调用完成),callcheck_output阻塞.

The main difference is that, while popen is a non-blocking function (meaning you can continue the execution of the program without waiting the call to finish), both call and check_output are blocking.

另一个区别在于它们返回的内容:

The other difference is in what they return:

方法 callcheck_output 实际上是, 阻塞 popen,使用 Popen 对象.例如,您可以获得 returncode 属性通过调用 Popen.returncode().

The methods call and check_output are, in fact, blocking wrappers of popen, using a Popen object. For example, you can get the returncode attribute by calling Popen.returncode().

这篇关于子流程模块中的 check_call check_output 调用和 Popen 方法之间的实际区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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