我是 c# / winforms 的新手,并尝试使用手刹批量转换视频剪辑。当进程在自己的窗口中打开而不重定向 Stdout/Stderr 时,转换本身正在工作。但是当我将输出重定向到 winforms 文本框时,只有第一个剪辑被转换。正如我在任务管理器中看到的那样,handbrake_Cli 已经打开但什么也没做。我认为任何缓冲区中都有一些 STDerr/STDout 并且正在等待刷新....但我不知道该怎么做。如果有人能给我一个提示会很高兴:-)
ProcessStartInfo info = new ProcessStartInfo(" \"" + textBoxHandbrakeCLI.Text + "\"");
process.StartInfo = info;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
process.Exited += new EventHandler(process_Exited);
process.EnableRaisingEvents = true;
eventHandled = new TaskCompletionSource<bool>();
//Redirect output
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.OutputDataReceived += (sender, eventArgs) => MyProcOutputHandler(sender, eventArgs);
process.ErrorDataReceived += (sender, eventArgs) => MyProcOutputHandler(sender, eventArgs);
foreach(pseudo)
{
process.Start();
if (!errorRedirect)
{
process.BeginErrorReadLine();
process.BeginOutputReadLine();
errorRedirect = true;
}
}
private void MyProcOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(outLine.Data);
WriteStatus(sb.ToString());
}
public void WriteStatus(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(WriteStatus), new object[] { value});
return;
}
try
{
textBoxAdvancedStatus.AppendText(Environment.NewLine + value);
}
catch
{
//stay calm
}
}