I need to exicute multiple lines of commands in CMD, how would I do that?

To write lines I'd just do stuff like this?

cmd.StandardInput.WriteLine("ipconfig");

That is after the process is started.

Would it automatically press enter or would I have to use

cmd.StandardInput.Flush();

GAME after some reading I have come up with two methods for this.

Write your Commands in a text file and save it as a .cmd and run that file or do the following.

Process p = new Process();
        ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = "cmd.exe";
        info.RedirectStandardInput = true;
        info.UseShellExecute = false;

        p.StartInfo = info;
        p.Start();

        using (StreamWriter sw = new StreamWriter(p.StandardInput))
        {
            if (sw.BaseStream.CanWrite)
            {
                sw.WriteLine("mysql -u root -p");
                sw.WriteLine("mypassword");
                sw.WriteLine("use mydb;");
            }
        }

Source: http://stackoverflow.com/questions/437419/execute-multiple-command-lines-with-the-same-process-using-net

Enjoy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.