小编dav*_*ave的帖子

如何在进程操作期间逐行捕获进程STDOUT和STDERR.(C#)

我将执行一个进程(lame.exe)将WAV文件编码为MP3.

我想处理进程的STDOUT和STDERR以显示进度信息.

我需要使用线程吗?我无法理解它.

一些简单的示例代码将不胜感激.

谢谢

c# stdout process stderr

17
推荐指数
3
解决办法
7284
查看次数

如何在运行System.Diagnostics进程时在线程之间传递对象

我不会提供所有代码,而是我想要做的一个例子.我有这个代码用于从外部进程stderr更新GUI元素.

我设置了这样的流程:

ProcessStartInfo info = new ProcessStartInfo(command, arguments);

// Redirect the standard output of the process. 
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.CreateNoWindow = true;

// Set UseShellExecute to false for redirection
info.UseShellExecute = false;

proc = new Process();
proc.StartInfo = info;
proc.EnableRaisingEvents = true;

// Set our event handler to asynchronously read the sort output.
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);
proc.Exited += new EventHandler(proc_Exited);

proc.Start();

// Start the asynchronous read of the sort output stream. Note …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading winforms

5
推荐指数
1
解决办法
769
查看次数

标签 统计

c# ×2

.net ×1

multithreading ×1

process ×1

stderr ×1

stdout ×1

winforms ×1