Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;


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

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


then myexe execute ok but i can not get output from the process,

I need both option true it is not execute

C#
procStartInfo.UseShellExecute = true;
            procStartInfo.RedirectStandardOutput = true;


Please solve this
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900