#include <unistd.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int f1[2], f2[2];
char buff;
if(pipe(f1) != -1);
printf("Pipe1 allright! \n");
if(pipe(f2) != -1);
printf("Pipe2 allright \n");
if(fork()==0)
{
close(1);
dup(f1[1]);
close(0);
execlp("ls", "ls", "-l", NULL);
}
else
{
if(fork()==0)
{
close(0);
dup(f1[0]);
close(1);
dup(f2[1]);
execlp("grep", "grep", "^d", NULL);
}
else
{
if(fork()==0)
{
close(0);
dup(f2[0]);
execlp("wc", "wc", "-l", NULL);
}
}
}
return 0;
}
我正在尝试执行ls -l | grep^d | wc -l in C.fork,execlp在Linux中
我试过每一个...
什么是错? :(
输出:PIPE1好吧!Pipe2好吧
PS你们的职位没有什么太大的上下文解释代码段;请更清楚地解释您的方案
'Ps'给我们写信,还是提醒自己? –
它适合我。对不起 – Domiik
你为什么要手动?你为什么不简单地使用'system(“ls -l | grep'^ d'| wc -l”);'? –