Using Code to Call an exe - then get the status back?

S

Simon Harvey

Hi all,

I need to make a scheduling service that will call an exe file.

As I understand it, the exe can return a status code from its Main method.

My question is, how do I programmatically:

a. Call the exe

b. Get the status code returned from the exe

I anyone could point me in the right direction I would be very grateful

Kindest Regards

Simon
 
M

Marc Gravell

See below - hope this helps. Note that more advanced options are available
via the Process and ProcessStartInfo classes - e.g. to control window
visibility, streaming IO, etc

Marc

===

using System;
using System.Diagnostics;

static class Program {
static void Main() {
using (Process proc = new Process()) {
proc.StartInfo = new ProcessStartInfo("notepad.exe");
proc.Start();
proc.WaitForExit();
Console.WriteLine(proc.ExitCode);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top