i would like to control a C program with a Python script. The C program look like this:
#include <stdio.h>
#include <stdlib.h>
void main(){
int num;
do{
printf("insert a number: \ninsert 3 to exit\n");
scanf("%d", &num);
switch(num){
case 1: {printf("you pressed 1\n");break;}
case 2: {printf("you pressed 1\n");break;}
default:{printf("you pressed another key\n");}
}
}while(num!=3);
}
and my python script is using subprocess:
import subprocess
p=subprocess.Popen('./Cprogram', stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write('1')
p.communicate()
and the result is that the python shell is blocked with the cursor on a empty line.
without the while in the c program the script works fine. How i could manage it ?
Thank you