将大量数据快速写入C子进程时,出现Broken Pipe错误。Python中的C子进程:sub.stdin.write IOError中断管道
process = subprocess.Popen("./gpiopwm", stdin=subprocess.PIPE)
while True:
process.stdin.write("m2000\n")
print "bytes written"
gpiopwm.c的主回路的Sectio:
所以我从一个Python脚本运行AC子
printf("1\n");
while (1) {
fgets(input,7,stdin); // Takes input from python script
printf("2\n");
numbers = input+1; // stores all but first char of input
char first = input[0]; // stores first char of input
if (first=='m') {
printf("3\n");
printf("%s\n",numbers);
}
}
然而,从这个输出如下:
1
bytes written
Traceback (most recent call last):
File "serial-receive-to-pwm.py", line 20, in <module>
process.stdin.write("m2000\n")
IOError: [Errno 32] Broken pipe
该C程序明显突破fgets
行,如2
从不打印。 我做错了什么?我怎样才能避免这种情况?
编辑: 我已更新fgets
行,以便它不包括取消引用参数,但仍然收到损坏的管道错误。
编辑:如果您尝试从控制台上运行你的C程序 input
被初始化为char *input="m2000";
请显示'input'的完整声明(以及可能的初始化)。 –