[Qt-interest] QProcess flush issue
Giuseppe D'Angelo
dangelog at gmail.com
Mon Oct 31 14:30:05 CET 2011
On 31 October 2011 12:21, Thiago Macieira <thiago at kde.org> wrote:
> On Monday, 31 de October de 2011 11:41:17 Etienne Sandré-Chardonnal wrote:
>> So the question is : why is the QProcess not able to read more frequently
>> from the standard output, where "cmd.exe" can? Is there anything
>> configurable somewhere to improve the buffer refresh frequency?
>
> I don't think there's anything wrong with Qt code. It reads as often as the
> underlying child process writes.
>
> You're probably running into a problem in the other application. The C
> library's behaviour is that stdout is line-buffered if it's connected to a
> terminal, but fully buffered if it's not. When QProcess spawns a child process,
> it's using a pipe (not a terminal), so the child process probably uses full
> buffering.
>
> You must cause it to flush its buffer more often. There's no workaround on
> Windows.
Out of curiosity: is it not possible under windows to inject some code
before running the other application (of course, assuming you're not
breaking any license agreement or any law by doing so)?
When I was a laboratory assistant for a UNIX/C course, I used the
following trick:
#include <stdio.h>
__attribute__((constructor))
void foo() {
setvbuf(stdout, (char*) NULL, _IONBF, 0);
}
Then compiled it inside a .so and loaded it with LD_PRELOAD. There's
no way of doing the same?
--
Giuseppe D'Angelo
More information about the Qt-interest-old
mailing list