0
當執行這一塊操作系統代碼我收到信息「退出值255」。我通過鍵盤接收命令,並且我得到了字符串正確的信息。當我收到錯誤信息時,程序不顯示(例如)鍵盤接收到的ls -lc WEXITSTATUS()退出255
printf("Command? ");
scanf(" %99[^\n]", str);
p = fork();
if(p > 0){ //Dad wait for the child
wait(&status);
if(WIFEXITED(status)){
printf("%d\n",WEXITSTATUS(status));
}
}else{ //Child execute the execlp
execlp(str, str,NULL);
exit(-1);
}
謝謝! Mark
'exit -1;'是原因。順便說一句:你進入scanf()行到底是什麼?注意:'ls -l'不是一個程序。 'ls'是。 – wildplasser
1)是的,現在幫助過程有一個狀態= 1這是很好的! 2)所以...我不能在execlp中使用ls -l? – Mark