Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell 1 is not capturing batch file output with tee

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?


1 Answers

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
like image 131
3 revsDangph Avatar answered Feb 25 '26 00:02

3 revsDangph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!