From 5bec1de7bce7c8c11f4cfa2e1db4fc1d64f24d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cchenyue=E2=80=9D?= <10195501438@stu.ecnu.edu.cn> Date: Fri, 12 Mar 2021 00:16:10 +0800 Subject: [PATCH] 3.11 commit --- fun_1.c | 4 --- fun_2.c | 92 ++++++++++++++++++++++++++++++++++++++++------------------------ main | Bin 22512 -> 23064 bytes 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/fun_1.c b/fun_1.c index 1570845..5a0a413 100644 --- a/fun_1.c +++ b/fun_1.c @@ -134,10 +134,6 @@ int builtin_cmd(char **argv) { return 1; } - if(!strcmp(argv[0], "&")) - { - return 1; - } return 0; } \ No newline at end of file diff --git a/fun_2.c b/fun_2.c index 7892d3c..9afceea 100644 --- a/fun_2.c +++ b/fun_2.c @@ -25,50 +25,72 @@ void print_his(char *argv) int Is_pipe(char **argv) { int i = 0; + int Ispipe = 0; char *cmd_0[MAXLINE]; char *cmd_1[MAXLINE]; while (argv[i]!=NULL) { - cmd_0[i] = argv[i]; - if(!strcmp(argv[i],"|")) + if (argv[i][0] == '|') { - cmd_0[i] = NULL; - i++; - while (argv[i]!=NULL) - { - cmd_1[i] = argv[i]; - i++; - } - cmd_1[i] = NULL; - shell_pip(cmd_0, cmd_1); - return 1; + Ispipe = 1; } i++; } - return 0; + if(Ispipe == 0) + { + return 0; + } + i = 0; + while (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_pip(cmd_0, cmd_1); + return 1; } -void shell_pip(char **cmd_0, char **cmd_1) -{/* - int pid; - int fd[2]; - pipe(fd); - pid = fork(); - if (pid == 0) - { - dup2(fd[0], 0); - close(fd[0]); - close(fd[1]); - -// mysys_simple(&Cmd[1]); - execvp(cmd_1[0],cmd_1); - exit(0); +void shell_pip(char **prog1, char **prog2) +{ + int des_p[2]; + if(pipe(des_p) == -1) + { + perror("Pipe failed"); + exit(1); } - dup2(fd[1], 1); - close(fd[0]); - close(fd[1]); - -// mysys_simple(&Cmd[0]); - execvp(cmd_0[0],cmd_0); -*/ + if(fork() == 0) + { + close(1); + dup(des_p[1]); + close(des_p[0]); + close(des_p[1]); + execvp(prog1[0], prog1); + perror("execvp of prog1 failed"); + exit(1); + } + if(fork() == 0) + { + close(0); + dup(des_p[0]); + close(des_p[1]); + close(des_p[0]); + execvp(prog2[0], prog2); + perror("execvp of prog2 failed"); + exit(1); + } + close(des_p[0]); + close(des_p[1]); + wait(0); + wait(0); + return 0; } \ No newline at end of file diff --git a/main b/main index 1f82560f9ee43e95a1b8424a801b1b63522769a5..c70b2b22cf645342dea409640fa56df9491ab596 100755 GIT binary patch delta 7920 zcmb7J4RjP$mVU1~)m_!q-RZ7Q(%m6H4f6lf2~h$h5t=|k2l)ws@S`9h5(qAkC_8 z4moG{<>cM>efPe5@B68$SJl_vrh5+47QbGhh6xsoQ(fV$HfNe!7k0nY^yyY#4eE z=Xe>fS2IsS7CjE$v*;vb)Eo%wA%4=qVhIy18*8iB&l7Tz*VWgOswb-+*;Y%|*41nz zk8G;hTE%)3wpodUe{8cnDnJST5#ok_EcK}yRRY?b>>YUm)!2W^zR4~_#p~Y83NEcs ziy7j$BWUn4pcFRB`X*J_CsrT(*y?bu5IP&^?CdtMw}7o4z&hC^TNZV*)ixhnWphM# z4$$e`zfrXe;FAXMdj{}gO}X~Zi5cHU8m}smX8D9KNFqBr>ZHDNk;YTXNv`jk@*&WD zqfSAcm>Gr^;_4_Wd%F6djQSZ8I72<>IDQu~u6R!e$8RCFAU?$Lj}RvyZsYhh#5gNG zEgZju7-z4if#Y3>ab|jIIerdsv|2%;f)m@(0M>-`lydwyVmsn6$B!b`5NC5-iP(WS z$nk@Sorv8Wmm$U_?I9e`L!5~C+TVZ}Rp<+LdB}6!xGxTl%ltY@hm!wg*x< zijKP9U}N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