Executing a C program from Python

Brent Bloxam brentb at beanfield.com
Mon Apr 6 20:49:29 CEST 2009

vishakha vaibhav wrote:
> Hi,
> I am very new to python. I have my cgi script written in Python. My 
> CGI script should call a C program and collect the value returned by 
> this program and pass it to the browser.
> Can anyone help me out in this. How can I execute the c program and 
> collect the return value.
> I tried,
> import os
> a=os.system("my-app")//my-app is the C program executable
> print a
> But the variable *a* prints 0 everytime. It should return a non-zero 
> value as per my C program.  Is there any method to do what I need.
> Regards,
> vish
> ------------------------------------------------------------------------
> --
> http://mail.python.org/mailman/listinfo/python-list
Executing from os.system returns the return code from the application. 
Take a look at the subprocess module 
(http://docs.python.org/library/subprocess.html#module-subprocess), as 
recommended by the os docs when you need to deal with capturing output 
from stdout.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090406/2fb6a38a/attachment.html>

More information about the Python-list mailing list