3

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 脚本和从属批处理文件的输出?

4

1 回答 1

5

编辑:

它似乎适用于 Powershell 2,但不适用于 Powershell 1。

不过,我找到了 Powershell 1 的解决方法。尝试将 test.ps1 更改为此

write-output "hello from PS"
.\test.bat | write-output
于 2009-09-18T15:36:07.443 回答