views:

433

answers:

1

PowerShell can call commandline batch files. PowerShell script output can be recorded with the "tee" command. But the tee command does not record the output of batch files inside a PowerShell script for me in PowerShell 1.

Try this cut-down example:

Make a batch file, called test.bat, with contents

@echo hello from bat

Run it from PowerShell:

PS C:\> .\test.bat | tee out.txt

This works - You will have an output file, containing

hello from bat

Now make a PowerShell script called test.ps1 that wraps the batch file, containing

write-output "hello from PS"
.\test.bat

Now run this with a tee:

 .\test.ps1 | tee pout.txt

This does not record the output of the batch files - the output file contains only

hello from PS

Whereas I expected

hello from PS
hello from bat

But no batch output is captured. How can I capture the output of this PowerShell script and subordinate batch files?

+4  A: 

EDIT:

It appears to work in Powershell 2, but not in Powershell 1.

I found a work-around for Powershell 1 though. Try changing test.ps1 to this

write-output "hello from PS"
.\test.bat | write-output
dangph
I am using PowerShell 1
Anthony
I have updated for your comments - used "@" in batch file, made it clear that this is PowerShell 1
Anthony
The workaround works for me too. We have a winner! So this must be something to do with the difference between write-console and write-output.
Anthony