首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用New-Object运行进程会将其隐藏

使用New-Object运行进程会将其隐藏
EN

Stack Overflow用户
提问于 2012-07-06 02:01:13
回答 1查看 1.1K关注 0票数 1

我需要从外部程序获取stdout,并将其带回Powershell。我找到并使用了@Andy Arismendi在这个问题( Redirection of standard and error output appending to the same log-file)中提供的答案。

下面的代码片段对我来说工作得很好,但是外部可执行文件在后台静默运行。有没有办法防止它被隐藏起来?

代码语言:javascript
复制
$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
EN

回答 1

Stack Overflow用户

发布于 2012-07-06 02:13:41

可以,您可以将UseShellExecute设置为true,但不能重定向输入和输出流。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11349946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档