开发者

redirect command output

folks, I need to redirect command output to 2 files, in one file redirect stdout stream, to another file redirect stder开发者_如何学Pythonr stream. Is it possible to do in cmd, PowerShell on windows ?


For powershell

Let us say you have my.ps1 like below:

"output"
Write-Error "error output"
exit 1

You can do:

.\my.ps1 2>stderr.txt | Tee-Object -file stdout.txt

You get stdout and stderr in the corresponding files.

More on Tee-Object:

http://technet.microsoft.com/en-us/library/dd347705.aspx

More on capturing all streams:

https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=297055&SiteID=99


In Powershell you can redirect standard output and error using the well known redirection operators >, >>, 2>, 2>>.

First make sure to set:

$erroractionpreference.value__=1

Then use redirection.

Examples:

ls C:\ 2> stderror.txt > stdoutput.txt # write output on stdoutput.txt

ls foo 2> stderror.txt > stdoutput.txt # write output on stderror.txt unless foo exists

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜