[Intro Music]
We have just tried to send the data
from STDOUT and STDERR to
different files; and it was
successful. We have written
different streams to different
files. And actually we have tried
this part. There were two different
data streams STDOUT and STDERR,
and two different files. But what
if we want to send the data from
STDOUT data stream to STDIN of
other process. Let's try it using the
same approach as we used in
previous lectures. Let's go to the
terminal and let's suppose that we
want to redirect STDOUT of 'ls'
command to STDIN of 'cat' command.
Let's try approach that we have
used with files, 'ls', then comes
greater than, '>' operator that will
redirect actually STDOUT of 'ls'
command; and let's here write 'cat'
command, and let's press Enter, and I
see actually nothing. I could try
here add '1' because '1' is ID of
STDOUT, and press Enter, and again
nothing. And that means that with
this '>' operator, you are not
able to redirect data from STDOUT
or STDERR to STDIN of other process.
That's why here we see nothing.
If you want to do so, you need to
use other operator called pipe, '|', and
approach that is called Piping. With
piping you could send data from STDOUT
of one process to STDIN of
other process. Next, you are also
able to send STDOUT data flow from
this process to another STDIN
of other process, and so on. You could
pipe different processes one after
previous. But please notice that STDERR
data stream is not piped, and
you are able to write it to the
file same as we did in previous
examples, or you could still bring
it to the terminal, that is actually
a default action. All right, let's
try to use piping here in this
example with 'ls' and 'cat' processes;
and for that I'll type 'ls', then pipe, '|'
this vertical line, and here will be
'cat' like so. Press Enter, and now I
see a list of files and folders.
And that means that now STDOUT
from 'ls' process was sent to STDIN
of 'cat' process. Alright, but let me
demonstrate to you that pipe does not
send STDERR data stream. For
that I could use here 'cat' command
with some missing file, 'missing-file
.txt', like so; and then let's
suppose that I want to pipe result
of this command to another 'cat'
process, press Enter, and I see
error directly here in the
terminal. And that means that STDERR
data stream was not sent to
another process. Alright, that's
how you could pipe different
processes together. For example, let
me pipe another process 'echo'; and by
default this command will simply
print some text to the terminal and
this text will be supplied here as
argument. Let's type "Hello World".
And if I press Enter now I see
output from STDOUT data stream, and
it prints "Hello world". Now let's
suppose that I want to send the
result of this operation to another
command; and let's use here again
'cat'; and let's suppose that I want
to write result of 'cat' operation
from STDOUT to file; and here I
could use the following syntax
'>'; and here will
be 'hello.txt'. Again here following
will happen, STDOUT data stream of
this process will send data to STDIN
of 'cat' process, and STDOUT of
'cat' process will be stored in the
file hello.txt. If this file is
absent, it will be created.
Alright, let's try that. Enter. I see
nothing here in the terminal. But
if I list the contents of file
hello.txt, I see "Hello world".
That's how it works, and that's how
you're able to combine pipe, '|' operator
and redirect, '>' operator. Please note
again that redirect, '>' operator will
write contents only to file, it is
not capable of sending data to STDIN
of other processes. For that you
need to use pipe, '|' operator. Alright,
that's all for this lecture and
next let me summarize what we have
discussed over the course of the
previous lectures. I'll see you next. Bye-Bye.
[no audio]