Veröffentlicht 27. Juni 201213 j Hallo ich möchte über meine C# Konsolenanwendung einen CMD Befehl ausführen habe das über die Anweisung System.Diagnostics.Process.Start("cmd", "/c " + "ipconfig"); gemacht. Allerdings schließt er danach immer sofort das Fenster woran liegts? Was muss ich eventuell noch hinzufügen? Danke schon mal...
27. Juni 201213 j Allerdings schließt er danach immer sofort das Fenster woran liegts?Völlig normales Verhalten für Konsolenprogramme. Nimm mal /k statt /c.
27. Juni 201213 j Also ich mach das immer mit: public static string ShellExecute(string cmd, string args) { Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = cmd; p.StartInfo.Arguments = args; p.StartInfo.CreateNoWindow = true; //required to capture standard output p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); p.WaitForExit(); //read the command line output StreamReader sr = p.StandardOutput; return (sr.ReadToEnd()); }
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.