Programming Field

| (Pipe operator) - DOS/Command Prompt Reference

Treats the output of the command written in the left side of ‘|’ symbol as the input of the command written in the right side.


<command1> | <command2>


Usage of ‘|’

Pipe performs connecting the output of the left-side command to the input of the right-side command. By using pipe, connecting the output of a command to the input of another one can be written as one-liner. No need to use temporary file for data transfers between commands.

[MS-DOS only] To use pipe, ‘TEMP’ environment variable must be set.

[Windows NT series] [Extensions] When calling labels in batch files by using Call, you cannot transfer Call's output with pipe. (You can write its output to the file by using output redirect.)


Sample 1

type C:\config.sys | more

Outputs C:\config.sys by using Type command, but the content is output per screen by More command.

Sample 2

echo Y| del "%TEMP%\*.*"

Deletes files (not directories) in TEMP directory by using Del command. Del command with specifying such as "*.*" always prompts whether to delete, so you can send Y by using Echo and ‘|’, which will be the response of Del's prompt.