Diagnostics. Process - dump output to file

Hi, I need to write mysqldump result to a file with 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 the file this way ... I don’t want to read the output and then write it to the file, since mysqldump output can get really big ... Any solutions?

+3
source share
4 answers

Try running cmd.exe and run the command so that your program does not overload the redirection:

proc.StartInfo.FileName = "cmd.exe";
proc.startinfo.Arguments = 
    "/c \"mysqldump -u root -pPassword --all-databases\" > db.sql"
+5
source

If you can use a lot of output for an event proc.OutputDataReceived, the event handler simply writes the output to your file.

Read the MSDN article here

+1
source

, ShellExecute . , , , (, , / ), , .

0

Source: https://habr.com/ru/post/1773902/


All Articles