2012-07-05 68 views
1

我需要从外部程序获取标准输出并将其返回到Powershell。我发现并正在使用@Andy Arismendi从这个问题提供的答案(Redirection of standard and error output appending to the same log-file)。运行一个使用New-Object的进程隐藏它

下面的代码片段对我很好,但外部可执行文件在后台默默运行。有没有办法阻止它隐藏?

$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 
+0

它是一个窗口的应用程序吗? – zdan 2012-07-05 18:09:50

+0

是的,如果我通过'Start-Process'调用它,它会显示为一个单独的窗口。但是这并不能给我我需要的标准输出。 – Pat 2012-07-05 18:13:41

回答

0

是的,你可以设置UseShellExecutetrue,但你不能重定向输入和输出流,然后。

+0

这就是我所设想的,并且它也可以很好地使用'Start-Process',但我需要stdout。 – Pat 2012-07-05 18:14:30