PowerShell 1 未使用 tee 捕获批处理文件输出
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
Now run this with a tee:
.\test.ps1 | tee pout.txt
这不会记录输出批处理文件的数量 - 输出文件仅包含
hello from PS
我预期的
hello from PS
hello from bat
但没有捕获批处理输出。如何捕获此 PowerShell 脚本和附属批处理文件的输出?
PowerShell can call commandline batch files. PowerShell script output can be recorded with the "tee" command. But the tee command does not record the output of batch files inside a PowerShell script for me in PowerShell 1.
Try this cut-down example:
Make a batch file, called test.bat, with contents
@echo hello from bat
Run it from PowerShell:
PS C:\> .\test.bat | tee out.txt
This works - You will have an output file, containing
hello from bat
Now make a PowerShell script called test.ps1 that wraps the batch file, containing
write-output "hello from PS"
.\test.bat
Now run this with a tee:
.\test.ps1 | tee pout.txt
This does not record the output of the batch files - the output file contains only
hello from PS
Whereas I expected
hello from PS
hello from bat
But no batch output is captured. How can I capture the output of this PowerShell script and subordinate batch files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
它似乎可以在 Powershell 2 中工作,但不能在 Powershell 1 中工作。
不过,我找到了 Powershell 1 的解决方法。尝试将 test.ps1 更改为此
EDIT:
It appears to work in Powershell 2, but not in Powershell 1.
I found a work-around for Powershell 1 though. Try changing test.ps1 to this