简体   繁体   中英

C: Redirect output of system() to stderr

The C system() call runs a program and forwards both stdout and stderr of the command that is run to the stdout and stderr streams of the calling program.

Is it possible to redirect stdout from the command inside the system() call to the stderr stream of the calling program?

Just append 1>&2 to the command executed in your system call:


Example:

system("ls 1>&2");

will execute ls and redirect stdout (1) to stderr (2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM