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?


That is after the process is started.

Would it automatically press enter or would I have to use


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;

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

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


Be a part of the DaniWeb community

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