PDA

View Full Version : Qt3/Windows: QProcess and php-cli



zaphod.b
11th January 2012, 14:56
Hi all,

yes, Qt3 and Windows. Pita but can't help it. Hope there's a Qt veteran around...

Problem in short: Can't read from a php script's stdout.

At length:
I have used QProcess often and successfully, and for running php scripts, too.
But do so and communicate via stdin/stdout is a first.

From this

QProcess process_;
process_.clearArguments();
process_.addArgument("cmd");
process_.addArgument("/C");
process_.addArgument("type " + anyfile);

or even this (path omitted for brevity)

QProcess process_;
process_.clearArguments();
process_.addArgument("php");
process_.addArgument("-h");

I can read from stdout just fine, connecting to SIGNAL(readyReadStdout()).

Also, when I execute this "test.php" script from a DOS box

<?php
//$line = trim(fgets(STDIN));
echo "foo";
fprintf(STDOUT, "%s", "bar");
?>
it writes out "foobar" as expected.

However, running (again, paths omitted for brevity - QDir::convertSeparators() used but changes nothing)

QProcess process_;
process_.clearArguments();
//process_.addArgument("cmd"); //command interpreter makes no difference
//process_.addArgument("/C");
process_.addArgument("php");
process_.addArgument("test.php");
//process_.addArgument("php test.php"); //no matter if 1 or 2 args

the very same slot that got called before now is never executed.

I don't even know if it's a QProcess limitation, or a php one, or how I could make sure of one or other.

Any idea? Thx.

wysota
11th January 2012, 15:08
Make sure your QProcess object doesn't go out of scope before it has a chance to execute the script.

zaphod.b
11th January 2012, 15:15
I have.
Edit: I put the QProcess object definition there for completeness. In real, it is a member of a parent class which is assured to live on.

(I vaguely sensed I should've been less brief...)