#include #include #include #include static int num = 0; static char storage[MAXLINE][MAXLINE]; void history(char *cmdline) { strcpy(storage[num], cmdline); num++; } void print_history(char *argv) { int i = 0; if(argv == NULL) { for(; i') { if(fork() == 0) { if( (fd=open(prog2[0],O_RDWR | O_CREAT | O_NOCTTY | O_NDELAY))<0 ) { perror("open"); exit(0); } close(1); dup(fd); close(fd); execvp(prog1[0], prog1); remove(prog2[0]); exit(0); } wait(0); if(fork() == 0) { if( (fd=open(prog1[0],O_RDWR | O_NOCTTY | O_NDELAY))<0 ) { exit(0); } close(0); dup(fd); close(fd); execvp(prog2[0], prog2); exit(0); } wait(0); } if(Isopen == '<') { if(fork() == 0) { if( (fd=open(prog2[0],O_RDWR | O_NOCTTY | O_NDELAY))<0 ) { perror("open"); exit(0); } close(0); dup(fd); close(fd); execvp(prog1[0], prog1); exit(0); } wait(0); } return; } int Is_redirect(char **argv) { int i = 0; char Isopen = '0'; char *cmd_0[MAXLINE]; char *cmd_1[MAXLINE]; while (argv[i]!=NULL) { if (argv[i][0] == '>') { Isopen = '>'; } if (argv[i][0] == '<') { Isopen = '<'; } i++; } if(Isopen == '0') { return 0; } i = 0; while (argv[i][0] != '>' && argv[i][0] != '<') { cmd_0[i] = argv[i]; i++; } cmd_0[i] = NULL; i++; int j = 0; while (argv[i]!=NULL) { cmd_1[j] = argv[i]; i++; j++; } cmd_1[j] = NULL; shell_direct(cmd_0, cmd_1, Isopen); return 1; }