Ant*_*ony 2 powershell tee powershell-1.0
PowerShell可以调用命令行批处理文件.可以使用"tee"命令记录PowerShell脚本输出.但是,在PowerShell 1中,tee命令不会在PowerShell脚本中记录批处理文件的输出.
试试这个缩减的例子:
制作一个名为test.bat的批处理文件,其中包含内容
@echo hello from bat
Run Code Online (Sandbox Code Playgroud)
从PowerShell运行它:
PS C:\> .\test.bat | tee out.txt
Run Code Online (Sandbox Code Playgroud)
这有效 - 你将有一个输出文件,包含
hello from bat
Run Code Online (Sandbox Code Playgroud)
现在创建一个名为test.ps1的PowerShell脚本,该脚本包含批处理文件
write-output "hello from PS"
.\test.bat
Run Code Online (Sandbox Code Playgroud)
现在用发球台运行:
.\test.ps1 | tee pout.txt
Run Code Online (Sandbox Code Playgroud)
这不记录批处理文件的输出 - 输出文件仅包含
hello from PS
Run Code Online (Sandbox Code Playgroud)
而我的预料
hello from PS
hello from bat
Run Code Online (Sandbox Code Playgroud)
但是没有捕获批量输出.如何捕获此PowerShell脚本和从属批处理文件的输出?
编辑:
它似乎在Powershell 2中有效,但在Powershell 1中没有.
我找到了Powershell 1的解决方法.尝试将test.ps1更改为此
write-output "hello from PS"
.\test.bat | write-output
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3545 次 |
| 最近记录: |