我有一个GUI程序,可以在这个GUI程序中调用cmd。在我的例子中,GUI调用robocopy将文件复制到文件服务器。我想在GUI中显示进度。那么如何获取robocopy的输出并将其显示在我的GUI上。
最诚挚的问候, Yongwei Xing
答案 0 :(得分:3)
使用StandardOutput
信息流:
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
// ...
// read from process.StandardOutput
或者,不是直接从StandardOutput
读取,而是可以调用BeginOutputReadLine
传递一个回调,该回调会在输出新行时告诉您。