Calling C programs

C

C GIllespie

Dear All,

I have a simple C program which outputs a string. I want to be able to call
this progam from python and assign the output to a variable. What's the best
way to do this?

I've tried

os.system('/tmp/hello')
and
os.execv('/tmp/hello',[' '])

but I can't seem to store the return value.

Many thanks

Colin
 
C

C GIllespie

from os import popen
print popen("/tmp/hello").read()

What about if I want to pass an argument?

I've tried

input,output=popen2('/tmp/hello')

input.write("Some string")

input.close() # I get an error here.

Thanks

Colin
 
P

Peter Maas

C said:
What about if I want to pass an argument?

Via commandline? This way:

print popen("/tmp/hello anArgument").read()

Mit freundlichen Gruessen,

Peter Maas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top