Powershell won't output to file

Hi,

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
ugebAsked:
Who is Participating?
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
0
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?
0
FOXActive Directory/Exchange EngineerCommented:
Out-file sends the results of the command you launched to a file.  

https://technet.microsoft.com/en-us/library/hh849882.aspx
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

aikimarkCommented:
you need to supply a file name parameter with the start-transcript command
0
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.
0
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
0
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.
0
Steven CarnahanNetwork ManagerCommented:
Okay, try this:

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

Open in new window

0

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?
0
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.
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.