PDA

View Full Version : QProcess and stdin



ithinkso
22nd May 2011, 07:41
Hi, i have a simple program like this:

int main()
{
int a;
printf("something\n");
scanf("%d",&a);
}

and i'm running this program with QProcess but QProcess dont want to emit readyReadStandartOutput() signal until i use write().
It is possible to read data from stdout before i write something to process's stdin? and i dont mean closeWriteChannel() coz i need to write some data later after i read from stdout.

sry for my bad english,
regards
ithinkso

stampede
22nd May 2011, 09:41
Probably the output is buffered, and you'll need to flush the buffer yourself.
Try this:


printf("something\n");
fflush(stdout);

ithinkso
22nd May 2011, 17:21
I can't integrate in this little cpp source code, I need to do something like console in simple c++ IDE, compiling, running works fine but its not interactive due to this problem with stdout buffer :/
It is possible to flush process stdout buffer from another process?

squidge
22nd May 2011, 19:54
Not that I'm aware of, Have you tried just sending something like "\n" ?

ithinkso
22nd May 2011, 23:34
It's "cheating" i think, i mean how do IDE program based on Qt works? They send '\n' to process?

wysota
23rd May 2011, 00:33
It is possible to flush process stdout buffer from another process?
You can request QProcess to create the stdin/stdout descriptors in unbuffered mode.

ithinkso
23rd May 2011, 01:23
You can request QProcess to create the stdin/stdout descriptors in unbuffered mode.

start() process with QIODevice::Unbuffered makes no changes, u mean other solution?

wysota
23rd May 2011, 06:21
start() process with QIODevice::Unbuffered makes no changes
Then it is not buffering that is to blame.