trouble with wrapping a c program
Sanne Korzec
sanne at kortec.nl
Fri Jul 24 08:34:53 EDT 2009
Hi Mailing,
I am using a c program, which first initializes for some seconds and then
waits for user input (keyboard) to type something. When enter is pressed the
c program continues.
I have wrapped this program in a python script, which starts the c program.
To start the c program, there are many options in python e.g.
Os.system os.popen or subprocess.popen
To me there does not seem to be a difference for starting the program. They
all work well.
However the problem occurs when I want to input data during this c program.
Using the keyboard and then enter in the c program prompt works, but I wish
to do this from the python script by sending the string from the python
script.
I am able to print the string from python with a print command or with a
stdout.write command. But this simply prints it to the prompt, the c program
does nothing with this printed string.
Is there a way to pipe, stream, or send this string to the running c
program?
All tutorials about piping I have read, seem to have to wait for the process
to finish. Or need the stdin string before starting the program.
Note that the c program is not finished when the input is needed, so I
cannot use subprocess.call or wait.
It is possible to give the user input in advance, but I do not want this,
because this makes everything much slower!
I really would like to do this during/while the c program is running.
I have created a thread and a small xmlrpc server for this and this works
fine. However I cannot seem to pass the string.
Here is a small fragment of my code:
#initialization
cmd = [a list of my program and arguments]
subprocess.Popen(cmd) #starts the c program
#somewhere along the way
Send_string(str):
#Sys.stdin = str
#subprocess.stdin = str
I have spent the entire night trying to get this to work, but I can't seem
to get it right. Any help is much appreciated. Also, if anybody could
explain me where the fuck-up in my brain is, I would be very happy..
Sanne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090724/46e39bd6/attachment.html>
More information about the Python-list
mailing list