2012-07-05 21 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