PIPE is a DCL command that executes one or more DCL command strings from the same command line. The PIPE command enables you to perform UNIX style command processing, such as command pipelining, input/output redirection, and conditional and background execution.
PIPE command-sequence [separator command-sequence]...
One of the following:
- DCL command: a DCL command string, which can include qualifiers, parameters, keywords, and values.
- Pipeline: a sequence of pipeline-segment commands connected by pipes, represented by the vertical-bar (|) separator. A pipeline-segment command is a DCL command that appears in a pipeline. The pipe connects the SYS$OUTPUT of one pipeline-segment command to the SYS$INPUT of the next command. The format of a pipeline is as follows:
pipeline-segment-command | pipeline-segment-command [|...]
- Subshell: one or more command sequences separated by separators and enclosed in parentheses. The format of a subshell is as follows:
(command-sequence [separator command-sequence]...)
Input/output redirection is allowed in a command sequence. The command before an angle bracket (> or <) redefines its SYS$INPUT, SYS$OUTPUT, or SYS$ERROR during execution. You cannot use angle brackets (<>) to represent a directory specification in a PIPE command because the PIPE command interprets angle brackets as input/output redirection syntax.
Determines the processing action of the command sequences specified in a PIPE command. The valid PIPE separators are described in the following table:
|Vertical bar (|)||Key pipe separator. The pipe connects the SYS$OUTPUT of one pipeline-segment command to the SYS$INPUT of the next command.|
|Semicolon (;)||Sequential execution. The command sequence following the semicolon (;) is executed after the preceding command sequence is completed. You must precede this separator with a blank space; otherwise, it is parsed as the Record Management System (RMS) file specification version number delimiter.|
|Double ampersand (&&)||Conditional execution (upon success). The command sequence following the double ampersand (&&) is executed only if the preceding command sequence succeeds. Note that any ampersand that precedes a character string without spaces in between is parsed as a conventional DCL symbol substitution expression rather than the background execution syntax.|
|Double vertical bar ((||))||Conditional execution (upon failure). The command sequence following the double vertical bar (||) is executed only if the preceding command sequence fails.|
|Single ampersand (&)||Background execution. All command sequences that precede the ampersand (&) are executed asynchronously in a subprocess environment. The & separator is similar to the SPAWN/NOWAIT command. Note that any ampersand that precedes a character string without spaces in between is parsed as a conventional DCL symbol substitution expression rather than the background execution syntax.|
|@TEE||Command file, TEE.COM. Used for redirecting output to two targets (for example, one output is directed to the next stage in pipeline, and the other to a file).|
In a PIPE command line, the "&" has the highest precedence, followed by "|", ";", "&&", and "||", which have equal precedence.
Multiple Command Execution
Multiple DCL commands are specified in a single PIPE command and executed sequentially. The syntax for multiple command execution is as follows: PIPE command-sequence ; command-sequence [; command-sequences]...
Conditional Command Execution
A command sequence is executed conditionally depending on the execution result of the preceding command sequence. Using the following form, command-sequence2 executes if, and only if, command-sequence1 succeeds:
PIPE command-sequence1 && command-sequence2
Using the following form, command-sequence2 executes if, and only if, command-sequence1 fails:
PIPE command-sequence1 || command-sequence2
Pipeline Command Execution
A pipeline is formed by connecting DCL commands with pipes as follows:
PIPE pipeline-segment-command | pipeline-segment-command [|...]
Each pipeline-segment command runs in a separate subprocess with its SYS$OUTPUT connected to the SYS$INPUT of the next pipeline-segment command. These subprocesses execute in parallel; however, they are synchronized to the extent that each pipeline-segment command, except the first, reads the standard output of its predecessor as its standard input. A pipeline finishes execution when the last pipeline-segment command is done. It is very common to use filter applications in a pipeline. A filter application is a program that takes data from SYS$INPUT, transforms it in a specific way, and writes it to SYS$OUTPUT.
Command sequences can be executed in a subprocess environment by using the subshell execution form:
PIPE ( command-sequence [separator command-sequence]... )
The command sequences in a subshell are executed in a subprocess environment. DCL waits for the subshell to complete before executing the next command sequence. The ( ) separator is similar to the SPAWN/WAIT command.
Command sequences can be executed in a subprocess environment by using the following form:
PIPE command-sequence [ separator command-sequence]... &
- To redirect SYS$INPUT:
PIPE command-sequence < redirected-input-file
- To redirect SYS$OUTPUT:
PIPE command-sequence > redirected-output-file
- To redirect SYS$ERROR:
PIPE command-sequence 2> redirected-error-file
A pipeline-segment command can also redirect its SYS$INPUT, SYS$OUTPUT, or SYS$ERROR; however, SYS$OUTPUT redirection is allowed only for the last pipeline-segment command, and SYS$INPUT redirection is allowed only for the first pipeline-segment command.
You can interrupt a PIPE command by pressing Ctrl/Y. If the PIPE command is executing in a pipeline or a subshell command sequence, the command sequence and the PIPE command are deleted. In this case, a CONTINUE command entered immediately after the interrupt will not resume the execution of the PIPE command.
If the PIPE command is executing a command sequence other than a subshell or a pipeline command sequence, DCL behaves as if the command sequence were entered as a DCL command without the PIPE command verb and interrupted by Ctrl/Y.
Each command sequence sets the global symbol $STATUS with a returned value after it finishes execution. The return status of the PIPE command is the return status of the last command performed in the last segment. If all segments fail with some of error and the last segment returns with success, the status returned to DCL is the success.
When a PIPE command is executed in a command procedure with the ON condition processing, the conditional execution of command sequences (&&, ||) takes precedence over the action previously specified by the ON condition statement.