2011-06-15 7 views
40

標準のWindows .cmdがファイルでは、私はやってするだけでstdoutにメッセージを送ることができます。cmdからstderrにメッセージを送信するにはどうすればよいですか?

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

答えて

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

を試してみてくださいをちょうどこれを試してみましたバッチファイル内からでも正常に動作します。

関連する問題