January 2019
Beginner
318 pages
8h 23m
English
Pipe is another form of redirection. This technique is used to pass information from one program to another. The | symbol denotes pipe. By using the pipe technique, we can use more than two commands in such a way that the output of one command acts as input to the next command.
Now, we are going to see how we can accept an input using pipe. For that, first we'll write a simple script that returns a floor division. Create a script called accept_by_pipe.py and write the following code in it:
import sysfor n in sys.stdin: print ( int(n.strip())//2 )
Run the script and you will get the following output:
$ echo 15 | python3 accept_by_pipe.pyOutput:7
In the preceding script, stdin is a keyboard input. We are performing a floor
Read now
Unlock full access