Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send a message to stderr from cmd?

Tags:

batch-file

cmd

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) ??? 
like image 633
steenhulthin Avatar asked Jun 15 '11 14:06

steenhulthin


People also ask

How do I send output to stderr?

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.

How do I redirect stderr and stdout to a file in Windows?

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# ).


1 Answers

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

like image 155
dolphy Avatar answered Sep 17 '22 14:09

dolphy