Here is a C# example where one can execute a program using the Process Class. The example launches notepad with an argument of a filename to open and waits for completion. When the user closes notepad, its return code is printed out.

Console.WriteLine("Running");

Process pr = new Process();

pr.StartInfo.FileName = "Notepad.exe";
pr.StartInfo.Arguments = "test.dat";
pr.Start();

while (pr.HasExited == false)
    if ((DateTime.Now.Second % 5) == 0)
    { // Show a tick every five seconds.
        Console.Write(".");
        System.Threading.Thread.Sleep(1000);
    }

One can extract any output that a program does to the command line by looking at the Process.StandardOutput Property if it is applicable.

Share