Passing C and C++ standard streams across a system() call

A system() call occurs when one z/OS® XL C/C++ program calls another z/OS XL C/C++ program by using the ANSI system() function, which z/OS XL C/C++ uses if you are not running with POSIX(ON). Standard streams are inherited across calls to the ANSI system() function. With a POSIX system() function, file descriptors 0, 1, and 2 will be mapped to standard streams stdin, stdout and stderr in the child process. The behavior of these streams is similar to binary streams called with the ANSI system() function.

Inheritance includes any redirection of the stream as well as the open mode of the stream. For example, if program A reopens stdout as "A.B" for "wb" and then calls program B, program B inherits the definition of stdout. If program B reopens stdout as "C.D" for "ab" and then uses system() to call program C, program C inherits stdout opened to "C.D" for append. Once control returns to the calling program, the definitions of the standard streams from the time of the system() call are restored. For example, when program B finally returns control to program A, stdout is restored to "A.B" opened for "wb".

The file position and the amount of data that is visible in the called and calling programs depend on whether the standard streams are opened for binary, text, record I/O, or blocked I/O.

The behavior of the C standard streams across a system() call indicates the behavior of all standard streams since they are implemented in terms of the C standard streams.