Call C program

Dave Angel davea at ieee.org
Thu Dec 3 09:33:14 EST 2009


Patxi Bocos wrote:
> Hi!,
>
> I am developing a Python application and I need to call a C program which
> needs one parameter and it returns another one.
>
> How could I do it?
>
> Thanks :)
>
>   
You don't specify your python version, nor your OS.  And you don't 
really say what state that C program is in.

So I'll guess you're programming in Python 2.6, on Windows, and want to 
"call" an existing EXE file that happened to have been written in C, but 
which you don't want to modify.  Further, I'll assume the program is 
written to take its input from stdin, and outputs to stdout.

Use the subprocess module to run the EXE file.  You can supply a stream 
for stdin, and can capture stdout.

DaveA




More information about the Python-list mailing list