我需要从外部程序获取stdout,并将其带回Powershell。我找到并使用了@Andy Arismendi在这个问题( Redirection of standard and error output appending to the same log-file)中提供的答案。
下面的代码片段对我来说工作得很好,但是外部可执行文件在后台静默运行。有没有办法防止它被隐藏起来?
$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发布于 2012-07-06 02:13:41
可以,您可以将UseShellExecute设置为true,但不能重定向输入和输出流。
https://stackoverflow.com/questions/11349946
复制相似问题