Piping

Print Topic  Return to Overview  Previous Topic  Next Topic 

Piping is a special form of redirection, using an additional instance of TCC for each instance of the piping specified in the command line.

 

You can create a pipe to send the standard output of a command (command1) to the standard input of another command (command2), and optionally also send the standard error as well:

 

what is sent to pipe

command format

standard output only

command1 | command2

merge standard output and standard error

command1 |& command2

 

For example, to take the output of the ALIAS command (which displays a list of your aliases and their values) and pipe it to the external SORT utility to generate a sorted list, you would use the command:

 

alias | sort

 

To do the same thing and then pipe the sorted list to the internal LIST command for full-screen viewing:

 

alias | sort | list /s

 

The TEE and Y commands are "pipe fittings" which add more flexibility to pipes.

 

Like redirection, pipes are fully nestable. For example, you can invoke a batch file and send all of its output to another command with a pipe. A pipe on a command within the batch file will take effect for that command only; when the command is completed, output will revert to the pipe in use for the batch file as a whole. You may also have 2 or more pipes operating simultaneously if, for example, you have the pipes running in different windows or processes.

 

Processing each line received from a pipe

 

To process each line of text sent by the left side of a pipe in TCC, you may use the syntax below:

 

dir | for %file in (@CON:) command %file

 

This example shows how to pass each line of piped data to a command.

 

WARNINGS: TCC implements pipes by starting a new process for the receiving program. This process goes through the standard secondary shell start-up procedure, including execution of the TCSTART file, for EACH receiving program. All of the sending and receiving programs run concurrently; the sending program writes to the pipe and the receiving program reads from the pipe. When the receiving program finds an End of File signal, it finishes reading and processing the piped data, and terminates. When you use pipes with TCC, make sure you consider the possible consequences from using a separate process to run the receiving program, especially that it cannot create/modify/delete environment variables of the sending program, and inclusion of a command to change directories in the TCSTART file may cause the new process to execute in a different directory. When you use more than one pipe in a single command, e..g. the second example above with LIST, each pipe adds another instance of TCC.

 

Topic "piping.htm" last edited 1/28/2008. ©2008  JP Software, Inc.
Keywords: Piping,Standard Input,Standard Error,Standard Output,4START,TCSTART