I'm having problems reading/writing to stdin/stdout in a child process with subprocess.communicate().
This is the child process (in C)
#include <stdio.h>
int main ()
{
char buf[128];
printf("test\n");
gets(buf);
printf("%s", buf);
return 0;
}
This is the program in python that calls that child program
import subprocess
proc = subprocess.Popen('./test', stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdin, stderr = proc.communicate()
print stdin
proc.communicate(stdin)
stdin, stderr = proc.communicate()
print stdin
print stdin
I would expect this to print
test
input was test:
However, it seems that proc.communicate() causes an EOF for gets(), causing the child application to terminate. Is there anyway I can communicate with the child application without sending an EOF? IE I would like to read to the application AND THEN write to it.