Call External Program From Python And Get Its Output
I want to call a program (.exe), which is written in C++ and compiled, from Python. The executable takes as input two files and returns a score. I need to do this for multiple fil
Solution 1:
To run an external program and get its output, use subprocess.check_output
on Python 2.7+. The example from the docs:
>>> subprocess.check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
check_call
just returns the return code of the program, not the output.
Solution 2:
You can use the subprocess
module for that.
result = subprocess.check_output(['your_program.exe', 'arg1', 'arg2'])
Post a Comment for "Call External Program From Python And Get Its Output"