Does any magic "stdout" file exists?
This question already has an answer here:
Some utilities can not output to stdout.
It works. But sometimes I want to pipe the output to some other program like:
util out.txt | grep test
Does any magic "stdout" file in linux exists, so when I will replace the
out.txt above, it will work redirect the data to
发布者： 2017 年 12 月 27 日
Note: I know
util out.txt && cat out.txt | grep test, so please do not post answers like this.
/dev/stdout is a symlink to
/proc/self/fd/1 (see proc(5)).
IIRC some version of some programs (probably GNU awk) are handling specifically the
/dev/stdout filename (e.g. to be able to work without
/proc/ being mounted).
A common, but not universal, convention for program arguments is to consider
-, when used as a file name, to represent the stdout (or the stdin). For example, see tar(1) used with
If you write some utility, I recommend following that
- convention when possible and document if stdout needs to be seekable.
Some programs are testing if stdout or stdin is a terminal (e.g. using isatty(3)) to behave differently, e.g. by using ncurses. If you write such a program, I recommend providing a program option to disable that detection.作者: Basile Starynkevitch 发布者: 2017 年 12 月 27 日