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

Lieven Cardoen picture Lieven Cardoen · Dec 2, 2009 · Viewed 30.4k times · Source

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

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

Answer

Jonas Lincoln picture Jonas Lincoln · Dec 2, 2009

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();