Standard I/O and I/O Redirection

  Starting with version 2.0, DOS supports the UNIX-like concept of
  redirection of the Standard Input and Standard Output devices.  It is the
  basis of a technique which lets one program feed input into or capture
  output from another program.

  Unless redirected, Standard Input comes from the keyboard and Standard
  Output goes to screen; both are functions of the CON device.  A parent
  process (such as COMMAND.COM) can redirect either Standard Input or Output
  or both before passing control to a child process.  This can be a powerful
  way to pass information from process to process with a minimum of
  programming overhead.

  See File Handles for a list of pre-defined Standard I/O handles.

  Use DOS Character I/O functions or Fns 3fH/40H to read/write Standard I/O.
  Use file handle 02H (Standard Error device) with Fn 40H to make sure a
  message is displayed.

  Use DOS Fn 46H to redirect the Standard I/O.
  Use DOS Fn 4bH to execute a child process.
  Use DOS Fn 4400H to see if Standard I/O has been redirected.

  The Device Attribute of a device driver indicates if the device is to be
  used as the default Standard Input and/or Standard Output device.

█▌COMMAND.COM & Standard I/O▐█
  The DOS command processor examines each command line for I/O redirection
  symbols before it performs an internal command or EXECs a program:

   process < filespec   EXEC process; keyboard input will come from the file

   process > filespec   EXEC process; screen output will go to the file

   process >> filespec  EXEC process; output will be appended to the file

   process1 | process2  1. EXEC process1; output goes to temporary file
                        2. EXEC process2; keyboard input comes from the
                           temporary file
                        3. delete the temporary file

   Notes: ■ Output redirection with '>' creates the output file, truncating
            its length to 0 before the first characters are written.
            Use '>>' if you want to append text to the end of an existing

          ■ You can use the pipe ("|") symbol to chain several DOS commands
            and programs together:

              DIR | SORT | FIND /v "i" >myfile.txt

          ■ Each temporary pipe file will have a unique name formed from
            hex digits of the current date and time.

            Prior to DOS 3.0, the temporary files are created in the
            current default directory of the default drive.

            With DOS 3.0+, COMMAND.COM looks for the TEMP directory and
            puts temporary files there.  By setting TEMP to a RAM disk, I/O
            piping is much faster.

          ■ Redirection of the ECHO command is handy for several uses:
              ECHO ^L >PRN                (force a formfeed on the printer)
              ECHO y|DEL *.*   (answer "yes" to the "Are you sure?" prompt)
              ECHO ATDT 1(213)555-1234 >AUX                (dial the phone)

          ■ Redirect output to the NUL device to get rid of some DOS

              COPY *.COM d: >NUL     (avoid the "1 File(s) copied" message)

          ■ COMMAND.COM will ignore redirection symbols enclosed in quotes:

              REM I am using the greater-than sign ">" in this remark

See Also: Handle-Oriented File I/O
          DOS Functions