我在我的Powershell脚本中有一个批处理文件,我想运行它并将其输出写入文本文件 . 我尝试了以下方法:
Start-Process c:\path\file.bat | Out-File c:\path\output.txt
我也尝试使用Tee-Object和Write-Output代替Out-File,但没有任何内容写入文本文件 .
您可以使用 Start-Transcript 和 Stop-Transcript 让PowerShell控制台将所有控制台输出写入文本文件 .
Start-Transcript
Stop-Transcript
像这样使用它:
Start-Transcript -Path c:\temp\log.txt &c:\path\file.bat Stop-Transcript
有关详细信息,请参阅the documentation .
如果你想要bat文件的输出,例如构建脚本的结果,然后我发现以下效果最好:
$Product = 'ProductName' &C:\Path\$Product.bat | Out-File C:\Path\$Product-Output.txt
2 回答
您可以使用
Start-Transcript
和Stop-Transcript
让PowerShell控制台将所有控制台输出写入文本文件 .像这样使用它:
有关详细信息,请参阅the documentation .
如果你想要bat文件的输出,例如构建脚本的结果,然后我发现以下效果最好: