进程使用hellexecute = true并且还希望standardOutput = true

编程入门 行业动态 更新时间:2024-10-27 09:33:27
本文介绍了进程使用hellexecute = true并且还希望standardOutput = true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "myexe"); Process proc = new Process(); procStartInfo.WindowStyle = ProcessWindowStyle.Hidden; procStartInfo.UseShellExecute = false; procStartInfo.RedirectStandardOutput = true; //procStartInfo.CreateNoWindow = true; proc.StartInfo = procStartInfo; proc.Start(); string output = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(300); richTextBox1.Text=output;

当我运行此代码myexe生成错误时我更改

when i run this code myexe generate error and when i change

procStartInfo.UseShellExecute = true; procStartInfo.RedirectStandardOutput = false;

然后myexe执行好吧但是我无法从过程中获得输出, 我需要两个选项都是真的它没有执行

then myexe execute ok but i can not get output from the process, I need both option true it is not execute

procStartInfo.UseShellExecute = true; procStartInfo.RedirectStandardOutput = true;

请解决此问题

Please solve this

推荐答案

你不能。选项是互斥的。 打开ShellExecute告诉ProcessClass使用ShellExecute API函数执行命令而不是使用CreateProcess函数。 如果使用ShellExecute启动进程,则会失去对输入和输出流的访问权限。如果由ShellExecute启动,则无法访问流。 You can't. The options are mutually exclusive. Turning ShellExecute on tells the ProcessClass to use the ShellExecute API function to execute the command instead of using the CreateProcess function. If ShellExecute is used to start the process you lose access to the input and output streams. There is no way to get at the streams if launched by ShellExecute.

更多推荐

进程使用hellexecute = true并且还希望standardOutput = true

本文发布于:2023-11-24 09:59:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624756.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   hellexecute   standardOutput   true

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!