In what format does piped output get sent and received from one command/program to another?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
When a command is piped to another command in what way or in what format does the piped output exist/get sent? Is it a temporary file? Is it a string? And how does the command that receives the piped output decode/read that output?
Example:
echo "Someone string" | ./program | tail
Does the program "program
" receive the output of echo
as a file?
How would the program read in that input?
linux pipe command executable
add a comment |Â
up vote
2
down vote
favorite
When a command is piped to another command in what way or in what format does the piped output exist/get sent? Is it a temporary file? Is it a string? And how does the command that receives the piped output decode/read that output?
Example:
echo "Someone string" | ./program | tail
Does the program "program
" receive the output of echo
as a file?
How would the program read in that input?
linux pipe command executable
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
When a command is piped to another command in what way or in what format does the piped output exist/get sent? Is it a temporary file? Is it a string? And how does the command that receives the piped output decode/read that output?
Example:
echo "Someone string" | ./program | tail
Does the program "program
" receive the output of echo
as a file?
How would the program read in that input?
linux pipe command executable
When a command is piped to another command in what way or in what format does the piped output exist/get sent? Is it a temporary file? Is it a string? And how does the command that receives the piped output decode/read that output?
Example:
echo "Someone string" | ./program | tail
Does the program "program
" receive the output of echo
as a file?
How would the program read in that input?
linux pipe command executable
linux pipe command executable
asked 50 mins ago


Lion
836
836
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. The Unix/Linux systems allow stdout of a command to be connected to stdin of another command. You can make it do so by using the pipe character ‘|’.
Pipe is used to combine two or more command and in this the output of one command act as input to another command and this command output may act as input to next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes. The command line programs that do the further processing are referred to as filters.
This direct connection between commands/ programs/ processes allows them to operate simultaneously and permits data to be transferred between them continuously rather than having to pass it through temporary text files or through the display screen.
Pipes are unidirectional i.e data flow from left to right through the pipeline.
Syntax :
command_1 | command_2 | command_3 | .... | command_N
Example :
Listing all files and directories and give it as input to more command.
$ ls -l | more
The more
command takes output of ls -l
as its input. The net effect of this command is that the output of ls -l
is displayed one screen at a time. The pipes act as a container which take output of ls -l
and giving it to more
as input. This command does not use a disk to connect standard output of ls -l
to standard input of more
because pipe is implemented in the main memory.
In terms of I/O redirection operators, the above command is equivalent to the following command sequence.
$ ls -l -> temp
more -> temp (or more temp)
[contents of temp]
rm temp
More 1, 2, 3
add a comment |Â
up vote
2
down vote
./program
receives the output of echo
as a file, namely the standard stream file /dev/stdin
. Demo:
echo foo | wc -c
echo foo | wc -c /dev/stdin
Outputs:
4
4 /dev/stdin
Note: a stream file is somewhat different from a file stored on a disk. We can access data randomly in a regular file, but not in a streaming file. It's like the difference between a CD player and radio playing a song. On the CD player we can rewind, fast forward, seek, and skip songs. The radio just outputs (or streams) whatever the broadcaster is sending right now.
Where is the stream stored? The OS stores it in a temporary data buffer, the size of which varies between OSes. See How big is the pipe buffer?
add a comment |Â
up vote
1
down vote
It goes as a bit stream. That's how it's sent and how it's received. The interfaces are file descriptors (or handles). A simple file is also handled that way.
See:
- Standard streams on Wikipedia
- File descriptor on Wikipedia
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?
– Lion
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. The Unix/Linux systems allow stdout of a command to be connected to stdin of another command. You can make it do so by using the pipe character ‘|’.
Pipe is used to combine two or more command and in this the output of one command act as input to another command and this command output may act as input to next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes. The command line programs that do the further processing are referred to as filters.
This direct connection between commands/ programs/ processes allows them to operate simultaneously and permits data to be transferred between them continuously rather than having to pass it through temporary text files or through the display screen.
Pipes are unidirectional i.e data flow from left to right through the pipeline.
Syntax :
command_1 | command_2 | command_3 | .... | command_N
Example :
Listing all files and directories and give it as input to more command.
$ ls -l | more
The more
command takes output of ls -l
as its input. The net effect of this command is that the output of ls -l
is displayed one screen at a time. The pipes act as a container which take output of ls -l
and giving it to more
as input. This command does not use a disk to connect standard output of ls -l
to standard input of more
because pipe is implemented in the main memory.
In terms of I/O redirection operators, the above command is equivalent to the following command sequence.
$ ls -l -> temp
more -> temp (or more temp)
[contents of temp]
rm temp
More 1, 2, 3
add a comment |Â
up vote
4
down vote
A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. The Unix/Linux systems allow stdout of a command to be connected to stdin of another command. You can make it do so by using the pipe character ‘|’.
Pipe is used to combine two or more command and in this the output of one command act as input to another command and this command output may act as input to next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes. The command line programs that do the further processing are referred to as filters.
This direct connection between commands/ programs/ processes allows them to operate simultaneously and permits data to be transferred between them continuously rather than having to pass it through temporary text files or through the display screen.
Pipes are unidirectional i.e data flow from left to right through the pipeline.
Syntax :
command_1 | command_2 | command_3 | .... | command_N
Example :
Listing all files and directories and give it as input to more command.
$ ls -l | more
The more
command takes output of ls -l
as its input. The net effect of this command is that the output of ls -l
is displayed one screen at a time. The pipes act as a container which take output of ls -l
and giving it to more
as input. This command does not use a disk to connect standard output of ls -l
to standard input of more
because pipe is implemented in the main memory.
In terms of I/O redirection operators, the above command is equivalent to the following command sequence.
$ ls -l -> temp
more -> temp (or more temp)
[contents of temp]
rm temp
More 1, 2, 3
add a comment |Â
up vote
4
down vote
up vote
4
down vote
A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. The Unix/Linux systems allow stdout of a command to be connected to stdin of another command. You can make it do so by using the pipe character ‘|’.
Pipe is used to combine two or more command and in this the output of one command act as input to another command and this command output may act as input to next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes. The command line programs that do the further processing are referred to as filters.
This direct connection between commands/ programs/ processes allows them to operate simultaneously and permits data to be transferred between them continuously rather than having to pass it through temporary text files or through the display screen.
Pipes are unidirectional i.e data flow from left to right through the pipeline.
Syntax :
command_1 | command_2 | command_3 | .... | command_N
Example :
Listing all files and directories and give it as input to more command.
$ ls -l | more
The more
command takes output of ls -l
as its input. The net effect of this command is that the output of ls -l
is displayed one screen at a time. The pipes act as a container which take output of ls -l
and giving it to more
as input. This command does not use a disk to connect standard output of ls -l
to standard input of more
because pipe is implemented in the main memory.
In terms of I/O redirection operators, the above command is equivalent to the following command sequence.
$ ls -l -> temp
more -> temp (or more temp)
[contents of temp]
rm temp
More 1, 2, 3
A pipe is a form of redirection (transfer of standard output to some other destination) that is used in Linux and other Unix-like operating systems to send the output of one command/program/process to another command/program/process for further processing. The Unix/Linux systems allow stdout of a command to be connected to stdin of another command. You can make it do so by using the pipe character ‘|’.
Pipe is used to combine two or more command and in this the output of one command act as input to another command and this command output may act as input to next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes. The command line programs that do the further processing are referred to as filters.
This direct connection between commands/ programs/ processes allows them to operate simultaneously and permits data to be transferred between them continuously rather than having to pass it through temporary text files or through the display screen.
Pipes are unidirectional i.e data flow from left to right through the pipeline.
Syntax :
command_1 | command_2 | command_3 | .... | command_N
Example :
Listing all files and directories and give it as input to more command.
$ ls -l | more
The more
command takes output of ls -l
as its input. The net effect of this command is that the output of ls -l
is displayed one screen at a time. The pipes act as a container which take output of ls -l
and giving it to more
as input. This command does not use a disk to connect standard output of ls -l
to standard input of more
because pipe is implemented in the main memory.
In terms of I/O redirection operators, the above command is equivalent to the following command sequence.
$ ls -l -> temp
more -> temp (or more temp)
[contents of temp]
rm temp
More 1, 2, 3
edited 27 mins ago
Tomasz
8,26552560
8,26552560
answered 38 mins ago
Goro
3,82652053
3,82652053
add a comment |Â
add a comment |Â
up vote
2
down vote
./program
receives the output of echo
as a file, namely the standard stream file /dev/stdin
. Demo:
echo foo | wc -c
echo foo | wc -c /dev/stdin
Outputs:
4
4 /dev/stdin
Note: a stream file is somewhat different from a file stored on a disk. We can access data randomly in a regular file, but not in a streaming file. It's like the difference between a CD player and radio playing a song. On the CD player we can rewind, fast forward, seek, and skip songs. The radio just outputs (or streams) whatever the broadcaster is sending right now.
Where is the stream stored? The OS stores it in a temporary data buffer, the size of which varies between OSes. See How big is the pipe buffer?
add a comment |Â
up vote
2
down vote
./program
receives the output of echo
as a file, namely the standard stream file /dev/stdin
. Demo:
echo foo | wc -c
echo foo | wc -c /dev/stdin
Outputs:
4
4 /dev/stdin
Note: a stream file is somewhat different from a file stored on a disk. We can access data randomly in a regular file, but not in a streaming file. It's like the difference between a CD player and radio playing a song. On the CD player we can rewind, fast forward, seek, and skip songs. The radio just outputs (or streams) whatever the broadcaster is sending right now.
Where is the stream stored? The OS stores it in a temporary data buffer, the size of which varies between OSes. See How big is the pipe buffer?
add a comment |Â
up vote
2
down vote
up vote
2
down vote
./program
receives the output of echo
as a file, namely the standard stream file /dev/stdin
. Demo:
echo foo | wc -c
echo foo | wc -c /dev/stdin
Outputs:
4
4 /dev/stdin
Note: a stream file is somewhat different from a file stored on a disk. We can access data randomly in a regular file, but not in a streaming file. It's like the difference between a CD player and radio playing a song. On the CD player we can rewind, fast forward, seek, and skip songs. The radio just outputs (or streams) whatever the broadcaster is sending right now.
Where is the stream stored? The OS stores it in a temporary data buffer, the size of which varies between OSes. See How big is the pipe buffer?
./program
receives the output of echo
as a file, namely the standard stream file /dev/stdin
. Demo:
echo foo | wc -c
echo foo | wc -c /dev/stdin
Outputs:
4
4 /dev/stdin
Note: a stream file is somewhat different from a file stored on a disk. We can access data randomly in a regular file, but not in a streaming file. It's like the difference between a CD player and radio playing a song. On the CD player we can rewind, fast forward, seek, and skip songs. The radio just outputs (or streams) whatever the broadcaster is sending right now.
Where is the stream stored? The OS stores it in a temporary data buffer, the size of which varies between OSes. See How big is the pipe buffer?
edited 12 mins ago
answered 37 mins ago
agc
4,1951935
4,1951935
add a comment |Â
add a comment |Â
up vote
1
down vote
It goes as a bit stream. That's how it's sent and how it's received. The interfaces are file descriptors (or handles). A simple file is also handled that way.
See:
- Standard streams on Wikipedia
- File descriptor on Wikipedia
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?
– Lion
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
add a comment |Â
up vote
1
down vote
It goes as a bit stream. That's how it's sent and how it's received. The interfaces are file descriptors (or handles). A simple file is also handled that way.
See:
- Standard streams on Wikipedia
- File descriptor on Wikipedia
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?
– Lion
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
It goes as a bit stream. That's how it's sent and how it's received. The interfaces are file descriptors (or handles). A simple file is also handled that way.
See:
- Standard streams on Wikipedia
- File descriptor on Wikipedia
It goes as a bit stream. That's how it's sent and how it's received. The interfaces are file descriptors (or handles). A simple file is also handled that way.
See:
- Standard streams on Wikipedia
- File descriptor on Wikipedia
edited 19 mins ago
answered 37 mins ago
Tomasz
8,26552560
8,26552560
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?
– Lion
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
add a comment |Â
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?
– Lion
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "
./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?– Lion
13 mins ago
So (correct me if I'm wrong) if I wanted a program (that I wrote) to read in the output of a command/program/process (let's say that simply prints to standard out a shape, say a square); "
./print_square | ./program
" ; From my program, I would need to read the piped output from standard-in as a string of bytes (a bit string) ? And from that string, I'd need to parse and figure out how to understand that string of bytes to be a square shape ?– Lion
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
I like your succinct answer, but would it be more accurate to call it a byte stream, since that's the smallest unit that can be written ?
– X Tian
13 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
@Lion Yes, the program you write should read from standard input, you can develop it by typing at the terminal or redirecting stdin from a file with a "canned" input. Then use it in a pipe stream later to read the output of the previous command.
– X Tian
6 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f470843%2fin-what-format-does-piped-output-get-sent-and-received-from-one-command-program%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password