Run a console application without DOS box

The example shows how to run a console application without the appearance of a DOS box. <br/> It also shows how to retrieve the console output.
// This snippet needs the "System.Diagnostics" // library // Application path and command line arguments string ApplicationPath = "C:\\example.exe"; string ApplicationArguments = "-c -x"; // Create a new process object Process ProcessObj = new Process(); // StartInfo contains the startup information of // the new process ProcessObj.StartInfo.FileName = ApplicationPath; ProcessObj.StartInfo.Arguments = ApplicationArguments; // These two optional flags ensure that no DOS window // appears ProcessObj.StartInfo.UseShellExecute = false; ProcessObj.StartInfo.CreateNoWindow = true; // If this option is set the DOS window appears again :-/ // ProcessObj.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; // This ensures that you get the output from the DOS application ProcessObj.StartInfo.RedirectStandardOutput = true; // Start the process ProcessObj.Start(); // Wait that the process exits ProcessObj.WaitForExit(); // Now read the output of the DOS application string Result = ProcessObj.StandardOutput.ReadToEnd();

Url: http://www.jonasjohn.de/snippets/csharp/run-console-app-without-dos-box.htm

Language: C# | User: ShareMySnippets | Created: Oct 16, 2013