I need to call the following command from C# code: mysql.exe --user=useranme --password=password --database=base < C:\backups\data.sql
I use:
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.FileName = "mysql.exe";
process.StartInfo.Arguments = "--user=useranme --password=password --database=base < C:\backups\data.sql";
process.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs args)
{
Console.WriteLine(args.Data);
});
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
But it does not work as a direct entry to the command line. I see that the right part "< C:\backups\data.sql" is not executed.
Help please.
this is because writing < filename at the command prompt force the shell to submit the content of the file c:\backups\data.sql in the standard input of your program. Passing the part after the '<' in the argument is not correct because you have to feed the stdin of your executable whith the content of the file.In order to do stdin/stdout redirection you can refer this question:
Redirecting stdin and stdout where stdin closes first
and you will push the content of your data.sql file onto the stdin stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With