Powershell won't output to file


I'm trying to capture a session in Powershell.  I do the following:

D:\coursera-dl-master> Start-Transcript

but this only contains the commands I type and not the output.  If I do "echo 1" I will see both the command and output separately, but if I execute a Python command from a .bat file, I don't see any of its output.

The same happens if I try a redirect like:

D:\coursera-dl-master> ./coursera-dl.bat {options ...}    > out.txt

How can I capture all output in a shell, including from batch scripts and Python programs?
LVL 11
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FOXActive Directory/Exchange EngineerCommented:
go with | out-file c:\pathtofile.txt

put the | at the end of the command with a space then the out-file command as shown above
ugebAuthor Commented:
I'm guessing pathtofile.txt is the output text file.  What is out-file then?

Can you give an example using 'echo' or something?
FOXActive Directory/Exchange EngineerCommented:
Out-file sends the results of the command you launched to a file.  

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

you need to supply a file name parameter with the start-transcript command
ugebAuthor Commented:
Okay, out-file is a program, got it. I got it to work with 'echo'.

I tried this:
D:\coursera-dl-master> ./coursera-dl.bat {options ...}    | out-file out2.txt

The file is empty.  The program coursera-dl.bat is producing errors and I'm trying to catch those, but this technique isn't catching errors.  Is there something special I have to do to catch errors into the file?

@aikimark: You don't need to specify a file, it will use its own file name and tell you what it is when you stop.
Steven CarnahanNetwork ManagerCommented:
Try adding -Append after the out2.txt

If that doesn't work then try this:

D:\coursera-dl-master> ./coursera-dl.bat {options ...} >> out2.txt
ugebAuthor Commented:
Sorry for the late response, I was out of town.

I had tried that 2nd one before, so I tried the append.  Unfortunately neither solution works.

It has something to do with the ability to capture std error text.  It can capture normal output, but not error text.
Steven CarnahanNetwork ManagerCommented:
Okay, try this:

D:\coursera-dl-master> ./coursera-dl.bat {options ...} 2>>out2.txt

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ugebAuthor Commented:
Yes, that did it, thanks!  Why does adding the '2' make it work?
Steven CarnahanNetwork ManagerCommented:
PowerShell writes its messages to different streams that can be redirected to files for capturing the respective output.
•Stream 1 (default): regular output ("STDOUT")
•Stream 2: error messages ("STDERR"), including error messages from external programs
•Stream 3: warning messages
•Stream 4: verbose messages
•Stream 5: debug messages

To capture a particular stream in a file you need to redirect the stream number to a file name. For instance you wanted error messages so you need to add the 2 to capture Stream 2.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.