0

I am trying to control and read the output of a 3rd party console application, of which source code I cannot change.

I want to use QProcess for this, but this should not matter, as the issue is the same when just using cmd: The 3rd party app seems to never call flush(). Therefore, directly calling it in cmd.exe works fine(Output appears in cmd window), but when calling e.g.

3rdPartyApp.exe > Output.txt

Output.txt stays empty until 3rdPartyApp.exe terminates or quits. After 3rdPartyApp.exe quits or is terminated, all stdout can be found in Output.txt .

Question: What can I do to create an environment where the buffer size of the pipe is limited, like when calling directly in cmd.exe, which seems to limit the buffer size to one line?

NTG
  • 73
  • 9
  • There's no simple fix if the application doesn't have a setting to use line buffering or no buffering. As is, the application detects that stdout is a pipe and switches to full buffering, which typically uses a 4 KB buffer. – Eryk Sun May 13 '18 at 13:07
  • BTW, it's not a "cmd window", and you're not running the application "in cmd". It's a "console window" (hosted by conhost.exe), and you're running the application "from cmd". A console application inherits the parent's console, or it allocates a new console if the parent has no console or if it's instructed to via the `CREATE_NEW_CONSOLE` creation flag. – Eryk Sun May 13 '18 at 13:10

1 Answers1

1

What you can do is create your own Console type application that will run 3rd party process and "handle" buffering of it. Then instead redirecting output of 3rd party application, you simply redirect output of proxy console app.

How to do it? You can read it here: https://www.codeproject.com/Articles/16163/Real-Time-Console-Output-Redirection

The author provides explaination and ready to use Console app called RTConsole.exe.

I had big time issue to get unbuffered output from 3rd party pyhton executable spawned from my .NET app and this RTConsole.exe saved me.

Sleeper
  • 61
  • 5