[英]Diagnostics.Process - Dump output to file
Hi I need to write the result of a mysqldump to a file with a standard windows commands. 嗨,我需要将mysqldump的结果写入带有标准Windows命令的文件。
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? 但它不会以这种方式写入文件...我不想读取输出然后将其写入文件,因为mysqldump输出可能变得非常大......任何解决方案?
Try executing through cmd.exe and enquote the command to keep your program from gobbling up the redirect: 尝试通过cmd.exe执行并引用命令以防止程序吞噬重定向:
proc.StartInfo.FileName = "cmd.exe";
proc.startinfo.Arguments =
"/c \"mysqldump -u root -pPassword --all-databases\" > db.sql"
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. 如果它是大量输出,您可以使用
proc.OutputDataReceived
事件,在事件处理程序中只需将输出写入您的文件。
Pretty much on similar lines, but written in VB.NET. 几乎在类似的行上,但用VB.NET编写。 Convert it and you should be good... http://blogs.msdn.com/b/rahulso/archive/2006/04/01/run-a-command-from-the-command-prompt-and-get-its-output-in-a-windows-application.aspx
转换它,你应该很好... http://blogs.msdn.com/b/rahulso/archive/2006/04/01/run-a-command-from-the-command-prompt-and-get-其输出-IN-A-Windows的application.aspx
For piped output you may need ShellExecute to be true . 对于管道输出,您可能需要ShellExecute为true 。 If that doesnt work, you may had to pipe it yourself (ie 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.
如果这不起作用,你可能不得不自己管道(即处理数据事件,或者有一个异步读/写循环),但是大小应该无关紧要,因为你应该只在任何时候读取它的小块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.