0

I'm calling qaac.exe (AAC encoder) from Process.Start(). The qaac.exe program outputs to the same line while it is encoding. I'm not sure what the technical term for it is, but it causes the program to not exit even though it is done processing the file. Here is my code:

string output = null;

var proc = new Process();

proc.StartInfo.FileName = "qaac.exe";
proc.StartInfo.Arguments = "-v256 -q2 file.wav";
proc.StartInfo.WorkingDirectory = @"C:\";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;

proc.Start();

output = proc.StandardOutput.ReadToEnd();
output += "\r\n";
output += proc.StandardError.ReadToEnd();

proc.WaitForExit();

If I pass in the -s argument (suppress console messages) to the qaac.exe app in the code above it works fine. So my question is how do I grab the output from an external program that writes to the same line in the console window?

Anger Density
  • 332
  • 1
  • 3
  • 17
iheartcsharp
  • 1,279
  • 1
  • 14
  • 22
  • Refer to [this link](http://stackoverflow.com/questions/2012509/process-standardoutput-readtoend-always-empty) Second answer (14+) – Graffito Jan 07 '17 at 00:52
  • Based on what little code you posted, and your described behavior, it seems almost certain that the "qaac.exe" program writes to both stdout and stderr, and since you are trying to read both synchronously, the "qaac.exe" process deadlocks. See marked duplicate for how to fix. If you believe you have some different problem, please improve your question so it includes a good [mcve] that reliably reproduces the problem. – Peter Duniho Aug 19 '19 at 17:39

1 Answers1

1

Is qaac.exe writing to StandardError? It could be that the buffer for it is filling up causing a deadlock as the Process.StandardOutput documentation mentions.

// To avoid deadlocks, use asynchronous read operations on at least one of the streams.
// Do not perform a synchronous read to the end of both redirected streams.

Guvante
  • 18,775
  • 1
  • 33
  • 64
  • AFAIK, `qaac` is not writing to `StandardError`. – iheartcsharp Jan 07 '17 at 00:26
  • @JMS10: If it is stalling without finishing you can use your debugger to figure out how far it is reaching before stalling. – Guvante Jan 07 '17 at 00:38
  • _"AFAIK, qaac is not writing to StandardError"_ -- if that's true, why does the code in your post redirect stderr and read from it? Have you tried _not_ redirecting stderr? Have you tried consuming stdout and stderr the _correct_ way, as in the marked duplicate (which @Guvante should have found and voted to close as a duplicate instead of answering again) – Peter Duniho Aug 19 '19 at 17:40