gpt4 book ai didi

PowerShell 1 不使用 tee 捕获批处理文件输出

转载 作者:行者123 更新时间:2023-12-02 23:06:22 26 4
gpt4 key购买 nike

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

现在用 T 恤运行它:

 .\test.ps1 | tee pout.txt

这不记录批处理文件的输出——输出文件只包含

hello from PS

我以为

hello from PS
hello from bat

但是没有捕获到批处理输出。如何捕获此 PowerShell 脚本和附属批处理文件的输出?

最佳答案

编辑:

它似乎在 Powershell 2 中有效,但在 Powershell 1 中无效。

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

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

关于PowerShell 1 不使用 tee 捕获批处理文件输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1445180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com