On Fri, Jul 24, 2009 at 5:34 AM, Sanne Korzec<sa...@kortec.nl> wrote: > 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. <snip> > 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? <snip> > Here is a small fragment of my code: > > #initialization > > cmd = [a list of my program and arguments] > > subprocess.Popen(cmd) #starts the c program
import subprocess cmd = [a list of my program and arguments] process = subprocess.Popen(cmd, stdin=subprocess.PIPE) #starts the c program line = raw_input("Please enter a line of input for the C program:") process.stdin.write(line) process.stdin.write("\n") You might want to study the docs for the subprocess module: http://docs.python.org/library/subprocess.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list