hakermania
30th August 2011, 20:52
I have exactly this problem described here: http://stackoverflow.com/questions/1052411/running-ping-with-qprocess-exit-code-always-2-if-host-reachable-or-not but the solution provided didn't solve my problem. I am at a linux machine as the guy who had the similar problem. In fact the code is like this:
QProcess *connected = new QProcess(0);
QString exec="ping";
QStringList params;
params << "-c" << "1" << "http://www.google.com";
connected->start(exec,params);
if(!connected->waitForFinished())
return false;
cout << "The exit code is " << connected->exitCode() << endl;
delete connected;
The ping process does execute and I always get the value '2' returned from connected->exitCode(). I have no idea why, but if I place instead of google.com the actual IP of google.com it seems to return the code correctly. But I don't know if google has static IP or not and I don't want to risk it anyway... Any suggestions or tips why is this happening and how to fix it :) ?
QProcess *connected = new QProcess(0);
QString exec="ping";
QStringList params;
params << "-c" << "1" << "http://www.google.com";
connected->start(exec,params);
if(!connected->waitForFinished())
return false;
cout << "The exit code is " << connected->exitCode() << endl;
delete connected;
The ping process does execute and I always get the value '2' returned from connected->exitCode(). I have no idea why, but if I place instead of google.com the actual IP of google.com it seems to return the code correctly. But I don't know if google has static IP or not and I don't want to risk it anyway... Any suggestions or tips why is this happening and how to fix it :) ?