Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <string.h>
- #include <libgen.h>
- #include <stdbool.h>
- int main(int argc, char **argv)
- {
- char input[256];
- char *argout[256];
- char * pch;
- int index;
- for(;;){
- printf("> ");
- fgets(input, sizeof(input),stdin);
- index=0;
- pch = strtok (input," \n ");
- while (pch != NULL){
- argout[index]=pch;
- index++;
- pch = strtok (NULL, " \n ");
- }
- argout[index]=NULL;
- if(strcmp(argout[0],"exit") == 0){
- return 0;
- }
- pid_t fpid;
- fpid=fork();
- if (fpid==0){
- execvp(argout[0],argout);
- }
- else {
- wait(NULL);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement