PowerShell 1 is not capturing batch file output with tee
PowerShell可以调用命令行批处理文件。 可以使用" tee"命令记录PowerShell脚本输出。 但是tee命令不会在PowerShell 1中为我记录在PowerShell脚本内的批处理文件的输出。
请尝试以下示例:
使用内容创建一个名为test.bat的批处理文件
1 | @echo hello from bat |
从PowerShell运行它:
1 | PS C:\\> .\\test.bat | tee out.txt |
这有效-您将有一个输出文件,其中包含
1 | hello from bat |
现在创建一个名为test.ps1的PowerShell脚本,该脚本将包装批处理文件,其中包含
1 2 | write-output"hello from PS" .\\test.bat |
现在使用T恤运行它:
1 | .\\test.ps1 | tee pout.txt |
这不会记录批处理文件的输出-输出文件仅包含
1 | hello from PS |
我期望
1 2 | hello from PS hello from bat |
但是没有捕获任何批处理输出。 如何捕获此PowerShell脚本和下级批处理文件的输出?
编辑:
它似乎可以在Powershell 2中工作,但不能在Powershell 1中工作。
我找到了Powershell 1的解决方法。 尝试将test.ps1更改为此
1 2 | write-output"hello from PS" .\\test.bat | write-output |