PRB: When Compiling with /P, Errors Are Directed to STDERR

ID Number: Q68834

6.00 6.00a 6.00ax 7.00 | 6.00 6.00a

MS-DOS | OS/2

Summary:

SYMPTOMS

The Microsoft C compiler can create a preprocessor listing by

compiling with the /P option. If this option is used in C version

6.0, 6.0a, 6.0ax, or 7.0 and output is redirected to a file,

preprocessor error messages that are generated will go to the

screen and not to the specified file.

CAUSE

This results from preprocessor errors being directed to STDERR,

rather than STDOUT.

This behavior is by design. Normally the output of the compiler is

syntax errors and warnings. However, when you are using the

preprocessing options, the output from the compiler is the

preprocessed output. Allowing preprocessor errors to be redirected

would result in the errors and warnings appearing in the

preprocessed file.

RESOLUTION

To resolve the problem, redirect STDERR to the file where you want

the error messages to go. This can been done in MS-DOS by using a

utility, such as ERROUT.EXE, that comes with C 5.1. Under OS/2,

the STDERR output can be redirected to a file by specifying the

handle for STDERR, which is 2, followed by ">" and then the name of

the file.

More Information:

The examples below demonstrate the syntax. For DOS using ERROUT.EXE,

use the following:

ERROUT /f err.txt cl /P example.c

For OS/2, use the following:

CL /P 2>outfile.txt example.c

Additional reference words: redirection 6.00 6.00a 6.00ax 7.00 C++