Tutorial :Can you execute another EXE file from within a C# console application?



Question:

Can you execute another EXE file from within a C# console application?

  • Can you pass arguments?
  • Can you get the exit code back?


Solution:1

Like this:

        var proc = new Process();          proc.StartInfo.FileName = "something.exe";          proc.StartInfo.Arguments = "-v -s -a";          proc.Start();          proc.WaitForExit();          var exitCode = proc.ExitCode;          proc.Close();  


Solution:2

Yes, yes and yes. See the System.Diagnostics.Process class.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »