简体   繁体   English

Diagnostics.Process - 转储输出到文件

[英]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事件,在事件处理程序中只需将输出写入您的文件。

Read the MSDN article here 阅读MSDN文章

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.

相关问题 防止Diagnostics.Process在完成后关闭 - Prevent Diagnostics.Process to close after finish 将提示输入发送到Diagnostics.Process - Send prompt input to Diagnostics.Process PSExec:将C#控制台应用程序输出重定向到window / Diagnostics.Process? - PSExec: Redirecting C# console app output to window/Diagnostics.Process? Diagnostics.Process不使用adobe reader打开PDF文件 - Diagnostics.Process doesn't open PDF file using adobe reader Diagnostics.Process的替代品,可运行简单的shell命令! - Alternatives to Diagnostics.Process to run a simple shell command! 当 Webform 应用程序从 IIS 运行时,Diagnostics.Process 启动功能不起作用 - Diagnostics.Process start function not working when webform application run from IIS 如何获取System.Diagnostics.Process的输出? - How to get the output of a System.Diagnostics.Process? System.Diagnostics.Process:当我运行创建输出文件并写入内容的C ++程序时,未创建输出文件 - System.Diagnostics.Process: when I run a C++ program that creates an output file and writes something, the output file is not created 将进程内存转储到文件/从转储文件重新创建进程 - Dump a process memory to file / recreate process from dump file C# - 我无法将我的process-ish的输出转储到文件中 - C# - I can't dump to a file the output of my process-ish
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM