Shell Data Processing - Standard Output Stream (stdout)

Card Puncher Data Processing

About

The Standard Output Stream is the output stream of a command

This is a file descriptor linked to a 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:

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 

/dev/fd/1 (Docker)





Discover More
Card Puncher Data Processing
Ansible - Shell

This article shows how to execute a command via a shell with ansible and the ansible shell module use the stdout conditionaly
Card Puncher Data Processing
IO - Standard streams (stdin, stdout, stderr)

Standard Streams are the mechanism by which a process: receive data (stdin) and output data (stdout, stderr). In a shell, by default, they will: read input from the keyboard and write output...
Card Puncher Data Processing
Shell Data Processing - Cat command (short for concatenate)

cat generates a stream of data from one or more files It therefore concatenate files. Output file1.txt then file2.txt contents and redirect and create the file fileAll.txt Content of fileAll.txt...
Card Puncher Data Processing
Shell Data Processing - Command

command in a shell may have one of the following functions in a pipeline. a start command to create a input stream from a file from an terminal input or text a filter command to process a input...
Card Puncher Data Processing
Shell Data Processing - Echo

Echo is a command that accepts an argument as standard input, and echoes it back to the terminal as standard output.
Card Puncher Data Processing
Shell Data Processing - Filter (Stream Operator)

This page is pipeline operator in a shell language. They are known as filter in a shell language. It is a computer program or shell command (subroutine) that: read from standard input (stream)...
Card Puncher Data Processing
Shell Data Processing - Pipe ( command to command redirection)

The pipe is a redirection operator held to transmit the stream output (stdout or sterr) of a command to another as stream input. One or more pipe operators followed by command forms a pipeline. Control...
Card Puncher Data Processing
Shell Data Processing - Pipeline

A pipeline is a succession of command separated by a pipe operator. -- Malcolm Douglas McIlroy - Inventor of pipes and other wonders. The format for a pipeline is...
Card Puncher Data Processing
Shell Data Processing - Sed (Stream editor)

sed stands for stream editor. It is a filter program used for filtering and transforming text It: takes as input a standard stream input modifies it based on an expression, and returns it as...
Card Puncher Data Processing
Shell Data Processing - Standard Output Stream (stdout)

The Standard Output Stream is the output stream of a command This is a file descriptor linked to a application. your application or a terminal application (TTY or PTY) To create a file from...



Share this page:
Follow us:
Task Runner