the following "example.exe" C++ program:
int main(int argc, char *argv[]) { int number = 0; do { scanf("%d", &number); for(int x=1; x<=number; x++) { printf("%d n", x); } } while (number >= 1); return EXIT_SUCCESS; }
Code:
import subprocess, os PIPE = subprocess.PIPE p = subprocess.Popen("example.exe", stdin=PIPE, stdout=PIPE) p.stdin.write("10") p.stdin.flush() print p.stdout.read() #Deadlock print "End of Execution" os.system("PAUSE")