Consider the following code:
SIGNAL = 123
proc = subprocess.Popen("longrunning")
proc.send_signal(SIGNAL)
Now what I want is to get the exit code that has been returned from the code with exit()
.
Unfortunately, in Python I get only the signal number that the process was stopped with:
>>> proc.returncode == -SIGNAL
True
Try this:
proc = subprocess.call(["ls", "-alh"], stdout=subprocess.PIPE)
print proc
0
subprocess.call ends up calling Popen but I've found it's a bit less complicated to use.
The two are mutually exclusive. If you process is terminated as a result of getting a signal it won't get a chance to produce a return code with exit()
.
See man 2 waitpid
for explanation on the underlying system call mechanism.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.