我需要使用stdin/stdout将Python控制台程序(作为子流程)与Python进行接口。Python子流程模块 - 意外行为
C程序是多个O就越少:
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);
使用Python子模块,我需要从这项计划中,写的东西读取数据,然后再等等看。我用下面的代码:
>>> p=subprocess.Popen(['C:\T.exe'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
>>> o,i=communicate('123\n')
0的输出是:
input>>
input was: 123.000000
input>>
input was: 0.000000
input>>
input was: 0.000000
我期望子进程上输入等待,直到另一个O,I =通信()调用。为什么它会在没有任何输入的情况下进行到程序结束?如何解决它?
这在过去也曾让我咬过一次。 :) – Skurmedel 2010-06-28 09:12:59