我正在使用 ash 而不是 bash 开发嵌入式系统,并试图从交叉编译的 C 程序中调用脚本。
它正在工作,但不像我问的那样在后台进程中。事实上,似乎 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
为什么要这样做?