2011-06-15 61 views
40

在一個標準的Windows .cmd文件,我可以將消息發送到做簡單的標準輸出:如何從cmd向stderr發送消息?

echo message 

我怎樣才能將消息發送到標準錯誤?

比方說,我有劇本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) 
??? 

回答

45

您可以嘗試將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

15

嘗試echo message 1>&2

我我剛剛嘗試過這一點,似乎即使在批處理文件中也能正常工作。