대량의 데이터를 C 서브 프로세스에 매우 빠르게 쓰는 경우 브로큰 파이프 오류가 발생합니다. gpiopwm.c의 메인 루프의파이썬에서 C 서브 프로세스 : sub.stdin.write IOError 파손 파이프
process = subprocess.Popen("./gpiopwm", stdin=subprocess.PIPE)
while True:
process.stdin.write("m2000\n")
print "bytes written"
SECTIO :
그래서 내가 파이썬 스크립트에서 교류 하위 프로세스를 실행하고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
줄에서로 중단됩니다 10은 절대로 인쇄되지 않습니다. 내가 잘못 했나요? 어떻게 이것을 피할 수 있습니까?
편집 : fgets
행을 역 참조 인수를 포함하지 않지만 깨진 파이프 오류가 계속 발생하도록 업데이트했습니다.
편집 : 콘솔에서 C 프로그램을 실행하려고하면 input
가 char *input="m2000";
'input'의 완전한 선언 (및 가능한 초기화)을 보여주십시오. –