<分区>
我有以下任务:
Write a C program to read the names of two (or more) executable programs, and redirect the output of the first program to the input of the second program, output of the second program to the input of the third program, and so on...
我至少了解 shell 中管道的基础知识。但是,我不明白如何使用 C 管道在 C 中实现此任务。我不知道如何将一个程序的输出作为另一个程序的输入等等。例如,在 shell 中:
ls | wc | ./add
此处ls
列出文件,wc
给出列出文件的计数,./add
添加给出的数字>wc
.
我从哪里开始在 C 程序中实现管道?