如何从cmd向stderr发送消息?

时间:2011-06-15 14:28:09

标签: batch-file cmd

在标准的Windows .cmd文件中,我只需执行以下操作即可向stdout发送消息:

echo message

如何向stderr发送消息?

示例

假设我的脚本parent.cmd包含:

call child.cmd 1>>stdout.log 2>>stderr.log

和一个包含以下内容的孩子:

:: 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)
???

2 个答案:

答案 0 :(得分:57)

您可以尝试将STDOUT的句柄重定向到STDERR的句柄。在子进程中,使用句柄重定向执行回显:

:: 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

答案 1 :(得分:16)

尝试echo message 1>&2

我刚试过这个,它似乎工作正常,即使是在批处理文件中也是如此。

相关问题