About
The Standard Output Stream is the output stream of a command
This is a file descriptor linked to a application.
- your application
Operation
Create a file from a Standard Output Stream
To create a file from a standard output stream, you use the redirected
Example:
- The echo command with the argument Hello World create an output stream that we redirect into the file hello.txt
echo 'Hello World' > hello.txt
- The cat command will show us the content of the file
cat hello.txt
Hello World
Send the Standard Output Stream as the Input Stream of another command
The Standard Output Stream can become the standard input stream of another command with the pipe redirection operator.
Example:
echo Hello World | tr HW hw
hello world
/dev/stdout
/dev/stdout is a device file
- which is a link to /proc/self/fd/1
- that represents the standard output (stdout) of the current process (self)
In other word, /dev/stdout is a link to STDOUT of the process accessing it.
Example:
echo "Hello, World!" > /dev/stdout
- Redirect my STDOUT to my STDOUT
foo > /dev/stdout
It represents file descriptor 1.
Most systems provide symbolic links /dev/stdin, /dev/stdout, and /dev/stderr, which respectively link to the files 0, 1, and 2 in /proc/self/fd.
/var/log/stdout
/var/log/stdout is a file that can be used to store and persist the standard output (stdout) of specific processes or services.
They can therefore be analyzed later.
myapp > /var/log/stdout 2>/var/log/stderr
/proc/pid/fd/1
fd is a https://man7.org/linux/man-pages/man5/procfs.5.html subdirectory containing one entry:
- for each file which the process has open,
- named by its file descriptor,
- which is a symbolic link to the actual file.
Thus:
- 0 is standard input,
- 1 standard output,
- and so on.
For example, assuming that -i is the flag designating an input file and -o is the flag designating an output file:
app -i /proc/self/fd/0 -o /proc/self/fd/1
# same as
app -i /dev/stdin -o /dev/stdout