andrew Sullivan
andrew Sullivan

Reputation: 4084

call exe program in C#

How to call an exe, generated from one c# file, from another c# file?

Upvotes: 2

Views: 1368

Answers (3)

Patrick
Patrick

Reputation: 17973

If you want to generate the C# file before executing it you can use the CSharpCodeProvider to compile the C# file, and then use the Process class to execute the output file.

You can find examples of each in the provided links.

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129832

using System.Diagnostics;

string command = @"C:\tmp\myExe.exe -my -params";

ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command)
    {
        RedirectStandardOutput = true,
        UseShellExecute = false,
        CreateNoWindow = true
    };

using (Process proc = new Process())
{
    proc.StartInfo = procStartInfo;
    proc.Start();

    return proc.StandardOutput.ReadToEnd();
}

Upvotes: 3

Jouke van der Maas
Jouke van der Maas

Reputation: 4338

System.Diagnostics.Process.Start("Path to any file, including exes");

Upvotes: 1

Related Questions