How to execute commands in Command Prompt using c#

Posted by karthik on Stack Overflow See other posts from Stack Overflow or by karthik
Published on 2010-05-10T09:00:19Z Indexed on 2010/05/10 9:04 UTC
Read the original article Hit count: 268

Filed under:

I want to execute these steps in CMD using c#

1 - CD C:\MySQL\MySQL Server 5.0\bin

2 - mysqldump -uroot -ppassword sample> d:\Test\222.sql

On manually doing this, i will get file named "222.sql"

I am using the below code to do it, but missing something.. Nothing Happens

public void CreateScript_AAR()
    {
        string commandLine = @"CD C:\MySQL\MySQL Server 5.0\bin\mysqldump -uroot -ppassword sample> d:\Test\222.sql""";
        System.Diagnostics.ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo("cmd.exe");
        PSI.RedirectStandardInput = true;
        PSI.RedirectStandardOutput = true;
        PSI.RedirectStandardError = true;
        PSI.UseShellExecute = false;
        System.Diagnostics.Process p = System.Diagnostics.Process.Start(PSI);
        System.IO.StreamWriter SW = p.StandardInput;
        System.IO.StreamReader SR = p.StandardOutput;
        SW.WriteLine(commandLine);
        SW.Close();
    } 

© Stack Overflow or respective owner

Related posts about c#