0
我正在使用ash而不是bash的嵌入式系統上工作,並試圖從交叉編譯的C程序中調用腳本。用作bash系統調用的strcat結果不喜歡&符號
它正在工作,但不是像我在問它的後臺進程。事實上,它似乎是一個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
爲什麼這樣做呢?
如果`buf`是「大約20個字符」這已經是太短了! – Clifford 2010-12-06 19:52:25