Yongwei Xing
Yongwei Xing

Reputation: 13451

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

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

Upvotes: 5

Views: 2737

Answers (1)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422152

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.

Upvotes: 3

Related Questions