How can I call an external program with a python script and retrieve the output and return code?
I've developed a little library (py-execute) that allows you to execute external programs, retrieve the output and the retcode and, at the same time get output in console in real time:
>>> from py_execute.process_executor import execute
>>> ret = execute('echo "Hello"')
Hello
>>> ret
(0, 'Hello\n')
You can avoid printing to console passing a mock user_io:
>>> from mock import Mock
>>> execute('echo "Hello"', ui=Mock())
(0, 'Hello\n')
I wrote it because with plain Popen (In Python 2.7) I was having trouble executing commands with a long output