I’m trying to run some external executable code from within Python and then make use of the output.The code I’m using takes an external file and returns a single number (the number of images encoded in that file). When I run from the command line, I see the following:
me@ubuntu:~/nist/hsfsys/bin$ ./nummis /usr/local/hsfsys/data/by_class/4a/train_4a.mis
3962
Where 3962 is a correct output as near as I can tell
However, when I try to use subprocess from within Python, I get the following error:
me@ubuntu:~/nist/hsfsys/bin$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_output(["./nummis","/usr/local/hsfsys/data/by_class/4a/train_4a.mis"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 544, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['./nummis', '/usr/local/hsfsys/data/by_class/4a/train_4a.mis']' returned non-zero exit status 32
>>> subprocess.call(["./nummis","/usr/local/hsfsys/data/by_class/4a/train_4a.mis"])
3962
32
How should I interpret this “non-zero exit status 32” ? If something is wrong, why don’t I see it on the command line? If nothing is wrong, why is Python complaining & how can I get it to stop complaining?
The command line only reports the exit status when explicitly asked for it.
After calling your program from the command line, try
in order to show the exit status. If it shows
32as well, it is the called program which is guilty. It doesn’t properlyreturn 0;orreturn EXIT_SUCCESS;in itsmain().