Reputation: 161
I want to run all commands programmatically and the commands are like:
string mysql ="C:\Program Files\MySQL\MySQL Server 5.1\bin"
string command =" mysql.exe -u root -ppassword fabrica < c:/backup.sql";
I want to run these two lines using C#, how can I achieve this?
Upvotes: 0
Views: 3206
Reputation: 2612
EDITED : Now i know what you want to do exactly
Here is a code to make it in a method
string binary = @"C:\MySQL\MySQL Server 5.0\bin\mysqldump.exe"
string arguments = @"-uroot -ppassword sample"
ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo(binary, arguments);
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = System.Diagnostics.Process.Start(PSI);
Encoding encoding = p.StandardOutput.CurrentEncoding;
System.IO.StreamWriter SW = new StreamWriter(@"c:\backup.sql", false, encoding);
p.WaitOnExit();
string output = p.StandardOutput.ReadToEnd()
SW.Write(output)
SW.Close();
Good luck!
Upvotes: 3