[Tutor] Call an external program and capture its output (was: Q regarding external program calling)

Ben Finney ben+python at benfinney.id.au
Sat Nov 5 22:01:29 EDT 2016


"Clayton Kirkwood" <crk at godblessthe.us> writes:

> Looked all over, but haven't found the answer.

Did you look in the Python standard library documentation
<URL:https://docs.python.org/3/library/>?

> If I have a (windows) program which I wish to start, even shell
> scripts, and possibly capture the output from, how do I do that?

That depends on what “capture the output” means.

If you mean you want to capture the data in the ‘stdout’ and ‘stderr’
streams from the program, the standard library ‘subprocess’ module
<URL:https://docs.python.org/3/library/subprocess.html> is what you
want.

More generally, running different programs concurrently has a section
<URL:https://docs.python.org/3/library/concurrency.html> in the standard
library documentation.

> PS, also, please me to where I can find more. My searches were rather
> useless.

The Python documentation <URL:https://docs.python.org/3/> and Python
wiki <URL:http://wiki.python.org/> should always be early in your
repertoire of searches for Python functionality.

-- 
 \       “Few things are harder to put up with than the annoyance of a |
  `\                  good example.” —Mark Twain, _Pudd'n'head Wilson_ |
_o__)                                                                  |
Ben Finney



More information about the Tutor mailing list