Hallo ich habe eine Frage zu C# und Batch-Dateien. Ich möchte einen Stapelbefehl ausführen und die Ausgabe in einer Zeichenfolge in C# speichern. aber ich kann die Datei nur ausführen, aber nicht diesen Inhalt in einer Zeichenfolge speichern und in einem Textfeld anzeigen.Wie kann ich einen Stapelbefehl direkt in C# ausführen?
meine Batch-Datei:
@echo
"C: \ lmxendutil.exe" off -licstatxml -host serv005 -port 6200> C: \ Temp \ HW_Lic_XML.xml Notizblock C: \ Temp \ HW_Lic_XML.xml
Hier ist mein C# -Code:
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;
}
Ich möchte die Ausgabe ich ein Stingng und wenn ich das tun kann, will ich, dass ich keine Batch-Datei haben. ich will diesen batvchcommand direkt in C# machen ... kann ich das machen?
http://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp – Rahul
siehe mein update ... – Tarasov