0
我是新来的操作系统,我想执行下面提到的下面的命令,但我无法解决它为什么不起作用。执行ls -l | grep D |时出错grep De
我想执行的命令
ls -l | grep D|grep De
这是我的代码 -
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
int fd[2];
int fd2[2];
pipe(fd);
if(!fork())
{
pipe(fd2);
if(!fork())
{
close(0);
dup(fd[0]);
close(1);
close(fd[1]);
dup2(fd2[1],fd[0]);
close(fd[0]);
execlp("grep","grep","D",NULL);
}
else
{
close(fd[0]);
dup(fd2[0]);
close(fd[1]);
execlp("grep","grep","De",NULL);
}
}
else
{
close(1);
dup(fd[1]);
close(0);
execlp("ls","ls","-l",NULL);
}
return 0;
}
请帮我执行此命令。 感谢ü提前