Autor Beitrag
HJW
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Di 05.11.13 09:25 
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:
ausblenden volle Höhe C#-Quelltext
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 user profile iconTh69: Titel geändert.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 05.11.13 13:10 
Hallo und :welcome:

versuche mal "cmd /K", d.h.
ausblenden C#-Quelltext
1:
2:
3:
4:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = "/K";
// ...

Ansonsten könntest du auch eine temporäre Batch-Datei erzeugen und diese dann mittels "cmd" ausführen lassen.