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 successfully?
Is the return value equivalent to the exit staus of a shell command?
For example, will the following piece of code work for virtually any command on Linux?
cmd = "foo.txt > bar.txt" ret = subprocess.call(cmd, shell=True) if ret != 0: if ret < 0: print "Killed by signal", -ret else: print "Command failed with return code", ret else: print "SUCCESS!!"
Please enlighten me :-)
subprocess. check_output() is the one that runs the command and returns the return value. If you want the output write your value to STDOUT and use check_output() to get the value.
communicate() #Another way to get output #output = subprocess. Popen(args,stdout = subprocess. PIPE). stdout ber = raw_input("search complete, display results?") print output #... and on to the selection process ...
Subprocess call():Subprocess has a method call() which can be used to start a program. The parameter is a list of which the first argument must be the program name. The full definition is: subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False) # Run the command described by args.
CalledProcessError Exception raised when a process run by check_call() or check_output() returns a non-zero exit status. returncode Exit status of the child process.
Yes, Subprocess.call
returns "actual process return code".
You can check official documentation of Subprocess.call and Subprocess.Popen.returncode
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With