0

I have a piece of code that runs command line and do some stuff as beneath:

        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = "CMD.EXE";
        System.Console.WriteLine("please insert the path of working directory");
        string path = System.Console.ReadLine();
        psi.WorkingDirectory = path; //@"D:\Exercises\npp52\scintilla\src";
        psi.Arguments = "/C dir /s /b | cccc - --outdir=d:\\jon";
        psi.WindowStyle = ProcessWindowStyle.Normal;
        Process.Start(psi);
        // ... cut ...
        XmlTextReader reader = new XmlTextReader(@"D:\jon\anonymous.xml");
        while (reader.Read()) 
        {
            switch (reader.NodeType) { /* ... */ }
        }

The second piece does not wait until first piece is finished and then start. Particularly before first piece will produce anonimous.xml second piece is trying to take that xml.

Alex
  • 23,004
  • 4
  • 39
  • 73

1 Answers1

3

If you add this line:

Process.Start(psi);
psi.WaitForExit(); // <-- add this

Your code should wait for the process to end.

Alex
  • 23,004
  • 4
  • 39
  • 73