PDA

View Full Version : Ping and QProcess (exitcode() question)



hakermania
30th August 2011, 21: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 :) ?

wysota
30th August 2011, 22:16
ping might be requiring a tty.

thalis
30th August 2011, 23:25
Try removing "http://" in line 4.

params << "-c" << "1" << "www.google.com";

Ping expects an IP or an hostname, "http://" isn't part of the hostname.

hakermania
31st August 2011, 00:29
Try removing "http://" in line 4.

params << "-c" << "1" << "www.google.com";

Ping expects an IP or an hostname, "http://" isn't part of the hostname.
good point ;)