What is a practical difference between check_call check_output call, and Popen methods in the subprocess module?

后端 未结 2 1477
北海茫月
北海茫月 2021-02-01 07:30

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 som

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 08:08

    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:

    • popen returns a Popen object.
    • call returns the returncode attribute.
    • check_output returns the output of the command execution.

    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().

提交回复
热议问题