### Redirect Standard Streams

In C and C++ programs, the standard streams read from the keyboard and write to the screen. Many utilities included in IBM C and C++ Compilers and command line programs use the standard streams. When you launch a program from the operating system GUI, or want input and output operations on these streams to read from and write to files, you can redirect the standard streams.

The Presentation Manager (PM) interface uses the stdout and stderr streams somewhat differently than non-Presentation Manager programs. Strings written to stdout or stderr do not show up on the screen unless redirected.

There are two ways you can redirect the standard streams:

- From Within an Application
  To redirect C standard streams to a file from within your application, use the freopen library function. For example, to send your output to a file called pia.out instead of sending it to stdout, code the following statement in your program:

> >     freopen("pia.out", "w", stdout);

- From the Command Line
  To redirect C or C++ standard streams to a file from the command line, use the standard redirection symbols > and < with the file handles for standard streams. For example, to run the program bill.exe, which has two required parameters XYZ and 123, and redirect the output from stdout to a file called bill.out, use the following command:

> >     bill XYZ 123 > bill.out

> You can also use the file handles to redirect one standard stream to another. For example, to redirect stderr to stdout, you use the command:

> >     2> &1

You cannot use redirection from the command line for memory files.

Stream Processing
Standard Streams

Run Your Application
View Output to Standard Streams from PM Programs