Question

this->getMined.start("php", QStringList() << "get_cexio_BTC.php");
this->getMined.waitForFinished();
QByteArray output = getMined.readAll();

output: "Could not open input file: get_cexio_BTC.php\n"

Project files and get_cexio_BTC.php are in the same folder. I tried putting full path and changing first line to this->getMined.start("php get_cexio_BTC.php"); but it didn't help.

Was it helpful?

Solution

So if php is not found in the path, or didn't get loaded into the environment variables that QProcess is using, you could get an error like that.

Try printing out the environment variables:

qDebug() << "Process Environment" << myProcess.getProcessEnvironment().toStringList();

If under the PATH variable it doesn't mention the location of php.exe, it will fail.

You may need to specify php.exe instead of just php. If it is being found correctly, then you should be able to see the usage statement of the php command when it isn't ran with any input file.

http://www.php.net/manual/en/features.commandline.options.php

If that isn't the issue, then make sure that you are in the working directory that you think you are.

system("dir");

or

qDebug() << "current path" << QDir::currentPath();

You can change the current working directory in code, or specify it for a specific process or you can go and change it from Qt's Project Settings > Run > Working Directory.

And if you didn't already, be sure to check/print out the error string of your QProcess instance when it isn't doing what you want it to do.

qDebug() << "error string?" << myProcess.errorString();

And make sure you know to use forward slashes and quotes where appropriate. If you have an unquoted command line argument/filename, it may see spaces in your path as another option to process.

And lastly if you are on Windows 8 and you are accessing something on a network drive, you have to run a net use command to be able to access those paths from the commandline, even if they are mapped and working in Windows explorer.

Hope that helps.

OTHER TIPS

You can use QNetworkAccessManager to access a page on localhost to trigger the included PHP script.

for example if you have the following php page in your htdocs directory: test.php

// test.php
echo("hello world");

you can access your page : http://localhost/test.php

QUrl url("http://localhost/test.php");
QNetworkAccessManager nam;
QNetworkReply* reply = nam.get(QNetworkRequest(url));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top