Reputation: 22601
Hi I need to write the result of a mysqldump to a file with a standard windows commands.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.WorkingDirectory = "sample directory";
proc.StartInfo.FileName = "mysqldump";
proc.StartInfo.Arguments = "-u root -pPassword --all-databases > db.sql";
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
But it doesn't write to file this way... I don't want to read the output and then write it to file, since mysqldump output can become really big... Any solutions?
Upvotes: 3
Views: 2224
Reputation: 4968
Pretty much on similar lines, but written in VB.NET. Convert it and you should be good... Link
Upvotes: 0
Reputation: 14732
Try executing through cmd.exe and enquote the command to keep your program from gobbling up the redirect:
proc.StartInfo.FileName = "cmd.exe";
proc.startinfo.Arguments =
"/c \"mysqldump -u root -pPassword --all-databases\" > db.sql"
Upvotes: 5
Reputation: 7937
If it's a lot of output you can use the proc.OutputDataReceived
event, in the event handler just write the output to your file.
Upvotes: 1
Reputation: 1064044
For piped output you may need ShellExecute to be true. If that doesnt work, you may had to pipe it yourself (i.e. either handle the data events, or have an async read/write loop), but the size shouldn't matter since you should only be reading small chunks of it at any time.
Upvotes: 0