我正在使用execlp()
在子进程上执行命令并保存到管道中以供父进程读取,例如
int pipefd[2];
if (pipe(pipefd)) {
perror("pipe");
exit(127);
}
if(!fork()){
close(pipefd[0]);
dup2(pipefd[1], 1);
close(pipefd[1]);
execlp("ls", "ls", NULL);
} else {
close(pipefd[1]);
dup2(pipefd[0], 0);
close(pipefd[0]);
execlp("wc", "wc", NULL);
}
在某些情况下,父级不需要执行任何操作,而只是在屏幕上打印出管道的内容,我如何在屏幕上打印管道(由于未知的输出大小可能不存储到变量中)。