Can you execute another EXE file from within a C#

2019-01-17 03:42发布

问题:

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

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

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


回答2:

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