Redirecting input and output

QNX SDP8.0User's GuideUser

You can override the behavior of commands that read from, or write to, stdin, stdout, and stderr.

Most commands:

  • read their input from the standard input stream (stdin, or file descriptor 0), which is normally assigned to your keyboard
  • write their output to the standard output file (stdout, or fd 1), which is normally assigned to your display screen
  • write any error messages to the standard error stream (stderr, or fd 2), which is also normally assigned to the screen

Sometimes you want to override this behavior.

If you want a process to: Use this symbol:
Read from a file, or another device (input redirection) <
Write stdout to a file (output redirection) >
Write stdout to a file, appending to the file's contents (output append) >>
For example, the ls command lists the files in a directory. If you want to redirect to output of ls to a file called filelist, enter:
ls > filelist
You can specify a file descriptor for the above redirections. For example, if you don't want to display any error messages, redirect stderr to dev/null (a special file, also known as the bit bucket, that swallows any data written to it and returns end-of-file when read from):
my_command 2> /dev/null

For more information, see Input/output redirection in the entry for ksh in the Utilities Reference.

Page updated: