ciao ho una domanda per C# e file batch. Voglio eseguire un comando batch e salvare l'output in una stringa in C#. ma posso solo eseguire il file ma non salvare questo contenuto in una stringa e mostrarlo in una casella di testo.Come posso eseguire un comando batch in C# direttamente?
mio file batch:
@echo off
"C: \ lmxendutil.exe" -licstatxml -host serv005 -port 6200> C: \ Temp \ HW_Lic_XML.xml notepad C: \ Temp \ HW_Lic_XML.xml
Ecco il mio codice C#:
private void btnShowLicstate_Click(object sender, EventArgs e)
{
string command = "'C:\\lmxendutil.exe' -licstatxml -host lwserv005 -port 6200";
txtOutput.Text = ExecuteCommand(command);
}
static string ExecuteCommand(string command)
{
int exitCode;
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
exitCode = process.ExitCode;
process.Close();
return output;
}
Voglio che l'output sia a mio agio e se posso farlo voglio che non abbia un file batch. voglio fare questo batvchcommand direttamente in C# ... posso farlo?
http://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp – Rahul
guarda il mio aggiornamento ... – Tarasov