2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by finito
0

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();

Edited by GAME: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.