Reputation: 13106
I am trying to pipe the output of a script to a text file.
This works:
MyScript > c:\output.txt
The problem with this is that errors are not included in the output in the text file (on screen they are).
When do this:
MyScript 2>&1 c:\output.txt
No file is created (but I still see everything on the screen).
I'm using Powershell 3.0. What am I doing wrong?
Upvotes: 1
Views: 169
Reputation: 24709
I believe what you're looking for is:
MyScript > c:\output.txt 2>&1
The "> c:\output.txt" redirects STDOUT to a file
The 2>&1 redirects STDERR to STDOUT
When you've already done the STDOUT redirection, the result is redirection of both STDOUT and STDERR to c:\output.txt
With only "2>&1 c:\output.txt" you're redirecting stderr to stdout, but letting stdout still output to console, and merely supplying c:\output.txt as an unused parameter to your script.
Upvotes: 2