What is the return value of subprocess.call()?

后端 未结 3 1981
野性不改
野性不改 2020-12-28 12:17

I am not sure what the return value of subprocess.call() means.

  • Can I safely assume a zero value will always mean that the command executed suc

相关标签:
3条回答
  • 2020-12-28 12:50

    You are at the mercy of the commands that you call. Consider this:

    test.py

    #!/usr/bin/env python
    success=False
    if not success:
        exit()
    

    Then running your code (with cmd='test.py') will result in SUCCESS!!

    merely because test.py does not conform to the convention of returning a non-zero value when it is not successful.

    0 讨论(0)
  • 2020-12-28 12:51

    Yes, Subprocess.call returns "actual process return code".

    You can check official documentation of Subprocess.call and Subprocess.Popen.returncode

    0 讨论(0)
  • 2020-12-28 12:54

    It is the return code, but keep in mind it's up to the author of the subprocess what the return code means. There is a strong culture of 0 meaning success, but there's nothing enforcing it.

    0 讨论(0)
提交回复
热议问题