Browse Source

3.11 commit

master
陈越 3 years ago
parent
commit
5bec1de7bc
3 changed files with 57 additions and 39 deletions
  1. +0
    -4
      fun_1.c
  2. +57
    -35
      fun_2.c
  3. BIN
      main

+ 0
- 4
fun_1.c View File

@ -134,10 +134,6 @@ int builtin_cmd(char **argv)
{
return 1;
}
if(!strcmp(argv[0], "&"))
{
return 1;
}
return 0;
}

+ 57
- 35
fun_2.c View File

@ -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;
}

BIN
main View File


Loading…
Cancel
Save