c - I am trying to create a interactive shell -
i trying create interactive shell program prompts user command, parses command, , executes child process. here code have im not sure go after pleae !!!!
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 command executed nothing runs after line { commandlength=-1; }else { cout<<"work"<<endl; } cout<< commandlength<<endl; return commandlength; }
assuming shell()
being run within child process called fork()
, you'll need ensure parent process waits child process terminate. see wait(2)
family of functions.
additionally, you'll want retrieve exit status of said child process (again, see wait(2)
).
you can try implement stream redirection. assuming exercise, i'll leave additional research on how implement these things user :) -- dup(2)
.
Comments
Post a Comment