How to get the robocopy(or other cmd program) output in a WINForm?

c#, cmd, winforms

Solution

Use the `StandardOutput` stream:

process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;

// ...
// read from process.StandardOutput

Alternatively, rather than reading from `StandardOutput` directly, you can call `BeginOutputReadLine` passing a callback that will tell you whenever a new line is outputted.

Problem

I have a GUI program, which would call a cmd in this GUI program. In my case, the GUI call the robocopy to copy the file to a file server.And I want to show the progress in the GUI. So how can I get the output of the robocopy and display it on my GUI. Best Regards, Yongwei Xing

Original source