In a standard windows .cmd file I can send messages to stdout simply by doing:
echo message
How can I send a message to stderr?
Example:
Let's say I have the script parent.cmd containing:
call child.cmd 1>>stdout.log 2>>stderr.log
and a child containing:
:: Writes a message to stdout :: (which in the parent is piped to stdout.log) echo message :: Now I want to write a message to stderr :: (which in the parent is piped to stderr.log) ???
The regular output is sent to Standard Out (STDOUT) and the error messages are sent to Standard Error (STDERR). When you redirect console output using the > symbol, you are only redirecting STDOUT. In order to redirect STDERR, you have to specify 2> for the redirection symbol.
You can redirect stderr to stdout by using 2>&1 , and then pipe stdout into grep . what does &1 means? To specify redirection to existing handles, use the ampersand & character followed by the handle number that you want to redirect (that is, &handle# ).
You can try redirecting the handle of STDOUT to the handle of STDERR. In your child process, perform the echo with a handle redirect:
:: Writes a message to stdout :: (which in the parent is piped to stdout.log) echo message :: Now I want to write a message to stderr :: (which in the parent is piped to stderr.log) echo message 1>&2
Microsoft 'splainin it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With