PowerShell 1 does not capture tee package output file

PowerShell can invoke command line command files. PowerShell script output can be written using the "tee" command. But the tee command doesn't write the output of batch files inside PowerShell script for me in PowerShell 1.

Try this example:

Create a batch file called test.bat with content

@echo hello from bat

      

Run it from PowerShell:

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

      

It works. You will have an output file containing

hello from bat

      

Now create a PowerShell script called test.ps1 that wraps a batch file containing

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

      

Now run this with tee:

 .\test.ps1 | tee pout.txt

      

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

hello from PS

      

While i expected

hello from PS
hello from bat

      

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

+2


source to share


1 answer


EDIT:

It works in Powershell 2, but not Powershell 1.



I found work for Powershell 1. Try changing test.ps1 to this

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

      

+5


source







All Articles