2010-05-14 7 views
2

Comment appeler un exe, généré à partir d'un fichier C#, à partir d'un autre fichier C#?Appelez le programme exe en C#

+1

duplication possible de [Lancement d'une application (.EXE) à partir de C#?] (Http://stackoverflow.com/questions/240171/launching-a-application-exe-from-c) – James

Répondre

3
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(); 
} 
+0

+1 à 'proc. StandardOutput.ReadToEnd(); ' – mMontu

1

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

0

Si vous voulez générer le fichier C# avant de l'exécuter, vous pouvez utiliser le CSharpCodeProvider pour compiler le fichier C#, puis utilisez la Process class pour exécuter le fichier de sortie.

Vous trouverez des exemples de chacun dans les liens fournis.