cc-preprocessorstdoutstderrconsole-redirect

Redirecting stderr to file and stdout to console


dcc  -tPPCE200Z4VEN:simple -Xdialect-ansi -XO -g3 -Xsize-opt -Xsmall-data=0 -Xno-common -Xnested-interrupts -Xdebug-dwarf2 -Xdebug-local-all -Xdebug-local-cie -Xdebug-struct-all -Xforce-declarations -ee1481 -Xmacro-undefined-warn -Xlink-time-lint -W:as:,-l -Wa,-Xisa-vle -Xsmall-const=0 -Xforce-prototypes -Xpass-source -Xkeep-assembly-file -c -Xlint -Xenum-is-best -Xinline=0 -Xaddr-sconst=0x11 -Xaddr-sdata=0x11  -DDISABLE_MCAL_INTERMODULE_ASR_CHECK -DOSDIABPPC -DSC667349 -DFLASH_START -DV_SUPPRESS_EXTENDED_VERSION_CHECK -DV_USE_DUMMY_STATEMENT=STD_OFF -DEU_DISABLE_ANSILIB_CALLS -DMCAL_CER_VALIDATION -DOsAppMode=OSAPPMODEDEFAULT -DSKIP_MAGIC_NUMBER -DRTE_MICROSAR_PIM_EXPORT -DMEMIF_FAST_NVM_ACTIVATED=STD_ON -DESCLmgr_IsENABLED -DESCLmgr_CANrouting_RESvalidity=1 -DFEE_SWITCH_NOT_CONFIG_BLOCKS=STD_OFF -DFILL_NOINIT_WITH_ZERO -Dsrc -ID:\project\src -ID:\project\obj -E D:\project\src\hello.c 1> D:\project\obj\hello.i 2>&1

I am preprocessing a .c file (compiler wind river mpc ), then the stdout is redirected in the .i file and from the .i file, the .pp file is construcred. After that, I am redirecting the stderr to console (2>&1). Check the redirection at the end of the command line above.

I know there are a lot of question on this topic, but I am doing the correct redirectioning, yet the error appear in the .pp file:

# 4 D:\project\src\hello.c", line 5: error (dcc:1573): Only Debug builds are supported

Is this error actually from the stdout, can't it be splitted?


Solution

  • 2>&1 doesn't mean "redirect stderr to console", it means "redirect stderr to the same place as stdout currently goes". If you do the redirections in the other order -- 2>&1 1>hello.i instead of 1>hello.i 2>&1 -- then you will get the effect I believe you are looking for.

    You need to think of the redirections happening one at a time. If you say 1>hello.i 2>&1 then this happens:

    But if you say 2>&1 1>hello.i then this happens: