I need to interface a C console program (as subprocess) with Python using stdin/stdout.
the C program is more o less it:
tmp = 0.0;
printf("\ninput>>");
scanf_s("%f",&tmp);
printf ("\ninput was: %f",tmp);
tmp = 0.0;
printf("\ninput>>");
scanf_s("%f",&tmp);
printf ("\ninput was: %f",tmp);
tmp = 0.0;
printf("\ninput>>");
scanf_s("%f",&tmp);
printf ("\ninput was: %f",tmp);
>>> p=subprocess.Popen(['C:\T.exe'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
>>> o,i=communicate('123\n')
the output of o is:
input>>
input was: 123.000000
input>>
input was: 0.000000
input>>
input was: 0.000000
我希望子进程在输入之前等待,直到另一个O,i=CultAudio()调用。为什么它在没有任何输入的情况下进入程序的末尾?如何修复?