Я использую QProcess для получения пути haproxy.Это плохо работает в Macos, но отлично работает в Linux.
Это часть моего кода:
QString haProxyPath = NULL;
// try to find haproxy correctly
QProcess shellProcess;
shellProcess.start("/bin/sh");
shellProcess.write("which haproxy");
shellProcess.closeWriteChannel();
shellProcess.waitForFinished(-1);
haProxyPath = shellProcess.readAllStandardOutput().trimmed();
// linux shows the right path
// Macosx just show ""
qDebug() << "HAProxy Path " << haProxyPath;
// ha proxy location not found if output from command is empty
if (haProxyPath.isEmpty()) {
qDebug() << "HAProxy not found!";
return false;
}
Но если использовать which haproxy
на терминале Macosx, я могу получить правильное значение.
Я использовал документы QT для справки: http://doc.qt.io/qt-5/qprocess.html
Какая-то идея?
Я нашел один способ решить мою проблему, но я думаю, что это не лучший способ,Я проверяю, есть ли файл haproxy:
#if defined(Q_OS_MAC)
// verify if thw haproxy exist in Mac if not send an alert
QFileInfo check_haproxy_exist_osx("/usr/local/bin/haproxy");
if(check_haproxy_exist_osx.exists()){
haProxyPath = "/usr/local/bin/haproxy";
}
#endif