Python バージョン 2.7.9 を使用しています。Popen プロセスから行を読み取ろうとすると、プロセスが終了するまでスタックします。終了する前に標準入力から読み取るにはどうすればよいですか?
入力が '8200' (正しいパスワード) の場合、出力が表示されます。しかし、パスワードが '8200' から変更された場合、出力がないのはなぜですか?
サブプロセスのソース コード:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char password[10];
int num;
do
{
printf("Enter the password:");
scanf("%s", &password);
num = atoi(password);
if (num == 8200)
printf("Yes!\n");
else
printf("Nope!\n");
} while (num != 8200);
return 0;
}
Python ソース:
from subprocess import Popen, PIPE
proc = Popen("Project2", shell=True, stdin=PIPE,stdout=PIPE,stderr=PIPE)
#stdout_data = proc.communicate(input='8200\r\n')[0]
proc.stdin.write('123\r\n')
print proc.stdout.readline()