Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在powershell脚本中捕获批处理文件的输出_Powershell_Powershell 1.0 - Fatal编程技术网

在powershell脚本中捕获批处理文件的输出

在powershell脚本中捕获批处理文件的输出,powershell,powershell-1.0,Powershell,Powershell 1.0,我需要捕获从.ps1文件中运行的.bat文件创建的输出 我不熟悉powershell脚本,但我知道这不是正确的语法。这最能说明我需要发生什么 我需要执行facter.bat脚本,然后将其输出存储在$Body中,以便以后使用该文本 "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat" > $Body 这应该做到: $Body=&“C:\Program Files(x86)\Puppet Labs\Puppet\bin\fac

我需要捕获从.ps1文件中运行的.bat文件创建的输出

我不熟悉powershell脚本,但我知道这不是正确的语法。这最能说明我需要发生什么

我需要执行facter.bat脚本,然后将其输出存储在
$Body
中,以便以后使用该文本

 "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat" > $Body
这应该做到:


$Body=&“C:\Program Files(x86)\Puppet Labs\Puppet\bin\facter.bat”

如果需要将输出直接复制到另一个文件,可以使用以下命令

& "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat" | Out-File -FilePath "<FilePathToWrite>.txt"
&“C:\ProgramFiles(x86)\Puppet Labs\Puppet\bin\facter.bat”| Out File-FilePath.txt”

工作正常,感谢您的帮助。它工作正常,但此解决方案存在问题。这样做只包含标准输出,而不包含标准错误。我们也有办法抓住它吗?@piyussoni:2>&1