困惑于stdin、stdout和stderr?

310
我对这三个文件的用途感到相当困惑。如果我的理解正确,stdin是程序写入其请求以运行进程任务的文件,stdout是内核写入其输出并由请求该信息的进程访问的文件,stderr则是所有异常都输入的文件。但是当我打开这些文件以检查它们是否真的存在时,似乎没有任何迹象表明它们确实存在!

我想知道的是,这些文件的确切目的是什么,简单易懂的答案,尽量避免使用技术术语!

11个回答

0

这里有一篇关于 stdinstdoutstderr 的长文:

总结一下:

Streams Are Handled Like Files

Streams in Linux—like almost everything else—are treated as though they were files. You can read text from a file, and you can write text into a file. Both of these actions involve a stream of data. So the concept of handling a stream of data as a file isn’t that much of a stretch.

Each file associated with a process is allocated a unique number to identify it. This is known as the file descriptor. Whenever an action is required to be performed on a file, the file descriptor is used to identify the file.

These values are always used for stdin, stdout, and stderr:

0: stdin
1: stdout
2: stderr

具有讽刺意味的是,我在 Stack Overflow 上找到了这个问题和上面的文章,因为我正在寻找关于异常/非标准流的信息。所以我的搜索还在继续。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接