Executing an external program in Python…

There are several ways of executing an external program from Python, but I had
the problem to catch the standard output.

After a while I came to the following solution:

import os

# Executing a shell command
mycmd = "python mycode.py"
child_stdin, child_stdout, child_stderr = os.popen3(mycmd)

# Reading the output streams
my_output = child_stdout.read()
my_error = child_stderr.read()

print "my_output:", my_output
print "my_error:", my_error


Comments are closed.

Roberto Rocco Angeloni is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

Fatal error: Cannot access protected property ObjectMgr::$_verbose in /web/htdocs/www.roccoangeloni.it/home/wp/wp-content/themes/rra/include.php on line 22