Executing a C program from Python

2009-04-06 Thread vishakha vaibhav
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


Re: Executing a C program from Python

2009-04-06 Thread Brent Bloxam

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.
--
http://mail.python.org/mailman/listinfo/python-list