27

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

  • Can you pass arguments?
  • Can you get the exit code back?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244

1 Answers1

72

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();
Jonas Lincoln
  • 9,567
  • 9
  • 35
  • 49