Lanciare un exe e catturare l'output

mercoledì 17 novembre 2004 - 09.10

ffederico Profilo | Newbie

senza utilizzare api o wrapper, come posso lanciare un eseguibile in c#?

trinity Profilo | Guru

Classe System.Diagnostics.Process, metodo Start.

Guarda anche la classe ProcessStartInfo per le varie opzioni disponibili


Ciao
Fabio

ffederico Profilo | Newbie

per chi ne avesse bisogno, ecco come ho fatto

StreamWriter sw;
StreamReader sr;

Process p = new Process();
ProcessStartInfo psI = new ProcessStartInfo("cmd"); // cmd.exe

psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;

p.Start();

sw = p.StandardInput;
sr = p.StandardOutput;

sw.AutoFlush = false;
sw.WriteLine( comandoDaEseguire );

string sout = sr.ReadToEnd();

sw.Close();
sr.Close();

p.Close();
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5