[Tutor] Q regarding external program calling
Alan Gauld
alan.gauld at yahoo.co.uk
Sun Nov 6 04:09:24 EST 2016
On 06/11/16 01:44, Clayton Kirkwood wrote:
> Looked all over, but haven't found the answer. 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?
Others have already pointed you to the subprocess module.
The documentation there includes several examples.
On Windows it sometimes helps to start a program via the
"start" command.
eg
start notepad.exe
This also works with data files to start the associated
program:
eg
start myfile.txt
But otherwise it should just work as described in the docs.
You may need to find the full path to the executable.
If your program has a GUI however, accessing the output
becomes much more difficult and may not even be
possible. In that case you may need to resort
to driving it programmatically via its API using
a tool like pywin32 or ctypes.
Some popular programs such as Excel have dedicated
modules that you can use to read/write data.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list