本文介绍了进程使用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
发布评论