Can I start a process (using C# Process.Start()
) in the same console as the calling program? This way no new window will be created and standard input/output/error will be the same as the calling console application. I tried setting process.StartInfo.CreateNoWindow = true;
but the process still starts in a new window (and immediately closes after it finishes).
Start(ProcessStartInfo)Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component.
Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.
You shouldn't need to do anything other than set UseShellExecute = false
, as the default behaviour for the Win32 CreateProcess function is for a console application to inherit its parent's console, unless you specify the CREATE_NEW_CONSOLE flag.
I tried the following program:
private static void Main() { Console.WriteLine( "Hello" ); var p = new Process(); p.StartInfo = new ProcessStartInfo( @"c:\windows\system32\netstat.exe", "-n" ) { UseShellExecute = false }; p.Start(); p.WaitForExit(); Console.WriteLine( "World" ); Console.ReadLine(); }
and it gave me this output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With