문제

I need to capture the output created by a .bat file that is run from within a .ps1 file.

I'm new to powershell scripting but I know this isn't correct syntax. This best illustrates what I need to have happen.

I need to execute the facter.bat script then store its output in $Body so I can use that text later.

 "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat" > $Body
도움이 되었습니까?

해결책

This should do it:

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

다른 팁

If you need to copy the output directly to another file, you can use the following command

& "C:\Program Files (x86)\Puppet Labs\Puppet\bin\facter.bat" | Out-File -FilePath "<FilePathToWrite>.txt"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top