Why is python's subprocess.call implemented like this?

后端 未结 2 803
时光说笑
时光说笑 2021-02-13 17:21

The subprocess module has the convenience function call, which is implemented like this in both 2.6 and 3.1:

def call(*popenargs, **kwargs):
    ret         


        
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 17:58

    If all you want to do is run a command and get the exit status to determine if it succeeded or failed then you don't need to communicate with it via pipes. That's the convenience of the subprocess.call() method. There are other convenience functions in the subprocess module as well which encapsulate many of the common uses of using the Popen objects in an efficient manner.

    If you need to pipe the child processes stdout or stderr somewhere than don't use call(), use a Popen object and communicate() with it just as the docs state.

提交回复
热议问题