0
我正在嘗試創建一個交互式shell程序,提示用戶輸入命令,解析命令,然後用子進程執行它。這是我有的代碼,但我不知道該PLEAE幫助後去哪裏!我正在嘗試創建一個交互式shell
Int shell(char *cmd_str){
int commandLength=0;
cmd_t command;
commandLength=make_cmd(cmd_str, command);
cout<< commandLength<<endl;
cout << command.argv[0]<< endl;
if(execvp(command.argv[0], command.argv)==-1)
//if the command it executed nothing runs after this line
{
commandLength=-1;
}else
{
cout<<"work"<<endl;
}
cout<< commandLength<<endl;
return commandLength;
}
您可能會感到頭痛,但這裏有一個開始:http://rik0.altervista.org/snippets/csimpleshell.html只是複製代碼不會幫助您的教育。 –
此外,您將此標記爲c,但您使用的是cout,它是C++重要:c *不是* C++ – Pankrates