| United States-English |
|
|
|
![]() |
Shells: User's Guide: HP 9000 Computers > Chapter 23 Advanced Concepts and CommandsCoprocesses |
|
The Korn Shell provides a mechanism to spawn a child process connected by a pipe to the parent shell. The standard input and output of the spawned command can be written to and read from the parent shell. Placing the |& metacharacter after the command to be executed creates a special pipe where you can use the print -p command to write the standard input of the spawned command process and the read -p command to read from the output of the process. See Chapter 21 “Basic Shell Programming” for details on the print and read commands. These two-way pipes allow shell scripts to pass data out through a pipeline, process that data with a coprocess, and bring data back through the pipeline for further use by the script, without having to use temporary files to store the input or output data. For example, suppose you have a file, 2waypipe, containing this script:
When you execute the script:
it immediately executes the bs compiler/interpreter which allows addition and subtraction. The read statement reads from standard input the the typed numbers 12 and 12 as value1 and value2. In the print -p statement the numbers are piped to the spawned process bs and summed and the sum read back into the script using the read -p script. Then the values sum and pi are sent back to bs and result is read back into the script using read -p, again. Then the output is sent to standard output. There are some limitations on what you can do with two-way pipes:
|
|||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||