Advertisement
deimos

headless running?

Dec 17th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. ////////////////////////////////////////////////
  2. // Check if headless counterpart is running
  3. bool ApplicationUI::isHeadlessRunning()
  4. {
  5. qDebug() << "*** isHeadlessRunning";
  6.  
  7. QString program = "pidin";
  8. QStringList arguments;
  9. arguments << "-pYOUR_APP_NAME_SERVICE";
  10. QProcess *pidin = new QProcess(this);
  11. pidin->setReadChannel(QProcess::StandardOutput);
  12. pidin->start(program, arguments);
  13.  
  14. if (!pidin->waitForStarted())
  15. return false;
  16.  
  17. if (!pidin->waitForFinished())
  18. return false;
  19.  
  20. QByteArray result = pidin->readAllStandardOutput();
  21. QString pidin_output(result);
  22. pidin->deleteLater();
  23.  
  24. qDebug() << "*** pidin:";
  25. qDebug() << pidin_output;
  26.  
  27. if (pidin_output.contains("MY_APP_Service")) {
  28. qDebug() << "*** MY_APP_Service is running";
  29. emit headlessRunning(true);
  30. return true;
  31. } else {
  32. qDebug() << "*** MY_APP_Service is NOT running";
  33. emit headlessRunning(false);
  34. return false;
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement