[英]Handling pipes in C to create a shell
cat file.txt | grep hello
The way I see this is that cat file.txt
is executed and whatever is passed to the stdout is passed as input in a pipe to grep hello
. 我看到的方式是执行cat file.txt
并将传递到stdout的任何内容作为输入传递到grep hello
的管道中。 Then grep hello
finds all the occurrences that match hello
in the given input. 然后grep hello
在给定的输入中查找所有与hello
匹配的事件。
Here is my confusion: does grep hello
write back to the pipe so the parent process outputs whatever is in stdout? 这是我的困惑: grep hello
写回管道,以便父进程输出stdout中的内容? Or does grep hello
put its returned content in stdout? 还是grep hello
将返回的内容放入stdout? How does it work? 它是如何工作的?
I am asking this question because I am writing a shell in C. 我问这个问题是因为我正在用C编写Shell。
cat
's stdout is connected to grep
's stdin. cat
的stdout连接到grep
的stdin。 grep
's stdout is connected to the default location, probably the terminal. grep
的stdout连接到默认位置,可能是终端。 grep
doesn't feed its output back to cat
-- the pipe is unidirectional. grep
不会将其输出反馈给cat
管道是单向的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.