Hallo, ich soche nach einer Möglichkeit mehrere Kommandos in einem Prozess auszuführen.
Ich will einen Datenbankdienst stoppen,einen Dump erzeugen und den Dienst wieder starten.
Mein bisheriger Versuch sieht so aus:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
| public void executeCommand() { string[] settings = getSettings(); Hashtable mandant = getMandanten(settings[7]); Process p = new Process(); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.RedirectStandardInput = true; psi.UseShellExecute = false;
p.StartInfo = psi; p.Start();
using (StreamWriter sw = p.StandardInput) { if (sw.BaseStream.CanWrite) { sw.WriteLine(@"net stop Sage_Classic_line_database_40");
sw.WriteLine(settings[0]+" -u " + settings[5] + @" -p" +settings[6]+@" --add-drop-database --add-drop-table --add-locks --comments --create-options --flush-logs --single-transaction --routines sageclglobal > "+settings[2]+@"\sageclglobal.sql"); foreach (DictionaryEntry item in mandant) {
sw.WriteLine(settings[0] + " --user=" + settings[5] + @" --password=" + settings[6] + " --host=" + settings[3] + " --port=" + settings[4] + " --skip-opt --disable-keys --add-locks --create-options --compress --comments=1 --extended-insert --quick --single-transaction --routines --default-character-set=latin1" + item.Value + " > " + settings[2] + @"\"+item.Key+@"\CLMAN_SqlDump.MySql");
} sw.WriteLine(@"net start Sage_Classic_line_database_40"); } } } |
Ich sehe zwar ein cmd Fenster aufgehen, dies schließt sich jedoch sofort wieder und nimmt keine Parameter entgegen (wenn ich Kommandos wie 'pause' einstreue, um das Fenster offen zu halten und zu sehen, was passiert, geht es auch gleich wieder zu)
Sieht irgendjemand einen offensichtlichen Fehler oder hat einen anderen Vorschlag, wie ich das machen kann?
Moderiert von Th69: Titel geändert.