【发布时间】:2015-03-18 22:16:05
【问题描述】:
我希望 c 程序打印收到的 3 行。但结果是c程序不停地打印from c program:33333333。我不知道为什么fgets()在执行后没有消耗stdin。
# pin.py
from subprocess import Popen, PIPE
p = Popen("/home/jchn/pstdin",stdin=PIPE,stdout=None)
p.stdin.write("11111111")
p.stdin.write("22222222")
p.stdin.write("33333333")
pstdin.c的内容
# pstdin.c
#include <stdio.h>
int main(){
char a[10];
FILE* fd = fopen("output","w");
while (1){
fgets(a,10,stdin);
printf("--from c program--:%s",a);
}
}
【问题讨论】:
标签: python c subprocess popen fgets