C#에서는 완료하는 데 2 ~ 3 시간이 걸리는 타사 응용 프로그램을 시작합니다. 실시간으로 콘솔에 쓸 프로세스의 출력이 필요합니다. Microsoft의 웹 사이트에서 BeginOutputReadLine()
및 RedirectStandardOutput
에 대한 연구를 수행했지만 코드가 여전히 작동하지 않습니다.C# 프로세스의 출력을 실시간으로 표시합니다.
현재 내 코드는 프로세스가 완료 될 때만 출력을 표시합니다. 나는 그것이 어디 잘못되었는지 모른다.
static void Main(string[] args)
{
Process process;
process = new Process();
process.StartInfo.FileName = "C:\\ffmbc\\ffmbc.exe";
process.StartInfo.Arguments = "-i \\\\dssp-isi-t\\TMD\\B002C010_130520_R2R7.2398v5.mxf -an -vcodec libx264 -level 4.1 -preset veryslow -tune film -x264opts bluray-compat=1:weightp=0:bframes=3:nal-hrd=vbr:vbv-maxrate=40000:vbv-bufsize=30000:keyint=24:b-pyramid=strict:slices=4:aud=1:colorprim=bt709:transfer=bt709:colormatrix=bt709:sar=1/1:ref=4 -b 30M -bt 30M -threads 0 -pass 1 -y \\\\dss-isi-t\\MTPO_Transfer\\dbay\\B002C010_130520_R2R7.2398v5.mxf.h264";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.Close();
}
private static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
string line;
line = (outLine.Data.ToString());
Console.WriteLine(line);
}
@Xeano 정확히 같은 질문은 아니지만 예, 꽤 유사합니다. – feralin
이것은 꽤 정상적입니다. 프로세스의 출력을 리디렉션하면 버퍼링 된 출력으로 전환됩니다. 그것이 많은 텍스트를 침을 뱉어 내지 않으면 그 버퍼는 플러시되도록 충분히 채워지지 않습니다. 프로그램 코드를 수정할 수 없다면 아무 것도 할 수 없습니다. –