PowerShell 可以调用命令行批处理文件。可以使用“tee”命令记录 PowerShell 脚本输出。但是 tee 命令不会在 PowerShell 1 中为我记录 PowerShell 脚本中批处理文件的输出。
试试这个精简的例子:
制作一个名为test.bat的批处理文件,其中包含内容
@echo hello from bat
从 PowerShell 运行它:
PS C:\> .\test.bat | tee out.txt
这有效 - 您将有一个输出文件,包含
hello from bat
现在制作一个名为test.ps1的 PowerShell 脚本来包装批处理文件,其中包含
write-output "hello from PS"
.\test.bat
现在用 tee 运行它:
.\test.ps1 | tee pout.txt
这不记录批处理文件的输出 - 输出文件仅包含
hello from PS
而我期望
hello from PS
hello from bat
但是没有捕获批量输出。如何捕获此 PowerShell 脚本和从属批处理文件的输出?