bash 대신 ash를 사용하는 임베디드 시스템에서 작업 중이며 크로스 컴파일 된 C 프로그램에서 스크립트를 호출하려고합니다.strcat 결과를 bash 시스템 호출로 사용하면 앰퍼샌드가 좋지 않음
나는 묻고있는 것처럼 작동하지만 백그라운드 프로세스에서는 작동하지 않습니다. 실제로 strcat 명령이 작동하지 않는 것처럼 보입니다. 그러나 그것은 왜 저를 상상합니다.
C에서 다소 새로운 것이지만 분명해야합니다.
코드 :
char mycall[230] = "/home/root/myscript.sh ";
char inbackground[3]= " &";
// buf is initiated and will be used as a parameter, string length is about 20 characters
strcat(buf,inbackground);
strcat(mycall,buf);
printf("%s", mycall); // this will display the command and parameter that was stored with
// in buf correctly, but without the ampersand at the end
system(mycall); // executes correctly
화면 표시 :
sh: syntax error: "&" unexpected
가 왜 이런 일을합니까?
경우 "20 자"이미 너무 짧다! – Clifford
어떤 OS입니까? uCLinux? – AShelly