Using the redirection symbols

The following table lists the redirection symbols supported by z/OS® XL C/C++ (when not running under one of the z/OS UNIX shells) for redirection of C standard streams from the command line or from a system() call. 0, 1, and 2 represent stdin, stdout, and stderr, respectively.

Table 1. z/OS XL C/C++ Redirection symbols
Symbol Description
<fn associates the file specified as fn with stdin; reopens fn in mode r.
0<fn associates the file specified as fn with stdin; reopens fn in mode r.
>fn associates the file specified as fn with stdout; reopens fn in mode w.
1>fn associates the file specified as fn with stdout; reopens fn in mode w.
>>fn associates the file specified as fn with stdout; reopens fn in mode a.
2>fn associates the file specified as fn with stderr; reopens fn in mode w.
2>>fn associates the file specified as fn with stderr; reopens fn in mode a.
2>&1 associate stderr with stdout; same file and mode.
1>&2 associate stdout with stderr; same file and mode.
Notes:
  1. If you use the NOREDIR option on a #pragma runopts directive, or the NOREDIR compile-time option, you cannot redirect standard streams on the command line using the preceding list of symbols.
  2. If you want to pass one of the redirection symbols as an argument, you can enclose it in double quotation marks. For example, the following passes the string "here are the args including a <" to prog and redirects stdout to redir1 output a.
       prog "here are args including a <" >"redir1 output a"
  3. TSO (batch and online) and MVS™ batch support command line arguments. CICS® and IMS™ do not.
  4. When two options specifying redirection conflict with each other, or when you redirect a standard stream more than once, the redirection fails. If you do the latter, you will get an abend. For example, if you specify
       2>&1
    and then
       1>&2
    z/OS XL C/C++ uses the first redirection and ignores any subsequent ones. If you specify
       >a.out
    and then
       1>&2

    the redirection fails and the program abends.

  5. A failed attempt to redirect a standard stream causes your program to fail in initialization.
  6. The C standard streams can be redirected to large format sequential data sets. If this occurs, the stream will be reopened without repositioning (noseek). In this situation, the reopen is initially attempted with repositioning (seek), fails with an ABEND 213-14 or 213-16, and the stream is then reopened without repositioning.