Redirection Command Output

people, I need to redirect the output of the command to 2 files, redirect the stdout stream to one file, redirect the stderr stream to another file. Is it possible to do in cmd, PowerShell on windows?

+4
source share
2 answers

For powershell

Let's say you have my.ps1 as shown 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 threads:

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

+4
source

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

First, make sure you install:

  $ erroractionpreference.value __ = 1 

Then use redirection.

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

+1
source

All Articles