lanching a "*.exe" from Python ?

Jeff Shannon jeff at ccvcorp.com
Tue Nov 27 17:59:37 EST 2001


stefff wrote:

> Hello,
> I am a new python user and I would like to know if it is possible to launch
> an executable in python : ie I have a c compilled program (that I want run
> as fast as it possible) and I intend using python for GUI and I/O managing.
> And all my appologizes if it's in the tutorial !
> Thank in advance for any clue.
> Stéphane

There are a couple of ways that you can do this.

If you have the source of the program (and are authorized to change it...),
then you can convert it into a Python extension module, and call your C
functions directly from Python.  See the docs on "Extending and Embedding" for
lots of info about this.

If you can't modify the program, then you may need to use pipes.  Check the
docs for os.popen2().  The short description is that you call popen2() with the
program that you want to run, and it will return two file objects--a writeable
one that's the stdin for the program, and a readable one that's the stdout from
the program.  You write commands to the input file, read results from the
output file, and then do whatever you like with that data.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list