1

I have a need to grab the stdout from an external program and bring it back into Powershell. I found and am using the answer provided by @Andy Arismendi from this question ( Redirection of standard and error output appending to the same log-file).

The snippet below works great for me, however the external executable runs silently in the background. Is there a way to prevent it from hiding?

$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "myjob.bat"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = ""
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$output = $p.StandardOutput.ReadToEnd()
$output += $p.StandardError.ReadToEnd()
$output | Out-File $myLog -Append
Community
  • 1
  • 1
Pat
  • 1,173
  • 5
  • 19
  • 44
  • Yes it shows up as a separate window if I invoke it via `Start-Process`. But this doesn't give me the stdout that I need. – Pat Jul 05 '12 at 18:13

1 Answers1

0

Yes, you can set UseShellExecute to true, but you cannot redirect the input and output streams, then.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • That's what I had assumed, and it works fine with `Start-Process` too, but I need the stdout. – Pat Jul 05 '12 at 18:14