45 QObject(parent), mName(name), mLastExecutablePath(
"")
47 mProcess =
new QProcess(
this);
50 mProcess->setProcessChannelMode(QProcess::MergedChannels);
51 mProcess->setReadChannel(QProcess::StandardOutput);
63 return mProcess.data();
68 QString absolutePathToExe = this->getExecutableInBundlesAbsolutePath(executable);
70 this->
launch(absolutePathToExe, arguments);
75 if (executable.isEmpty() || this->
isRunning())
78 this->internalLaunch(executable, arguments);
83 return mProcess->state() == QProcess::Running;
88 return mProcess->write(data);
93 return mProcess->waitForStarted(msecs);
98 return mProcess->waitForFinished(msecs);
101 QString ProcessWrapper::getExecutableInBundlesAbsolutePath(QString exeInBundle)
103 QString absolutePathToExe = exeInBundle;
105 if (!QFileInfo(absolutePathToExe).isAbsolute())
108 absolutePathToExe = absolutePathToExe.trimmed();
109 absolutePathToExe = QDir::cleanPath(absolutePathToExe);
111 if (!QFileInfo(absolutePathToExe).exists())
112 reportError(QString(
"Cannot find %1 [%2]").arg(mName).arg(absolutePathToExe));
114 return absolutePathToExe;
117 void ProcessWrapper::internalLaunch(QString executable, QStringList arguments)
122 report(QString(
"Launching %1: [%2 %3]").arg(mName).arg(executable).arg(arguments.join(
" ")));
124 if(arguments.isEmpty())
125 mProcess->start(executable);
127 mProcess->start(executable, arguments);
129 mLastExecutablePath = executable;
void reportError(QString msg)
void launchWithRelativePath(QString executable, QStringList arguments=QStringList())
void launch(QString executable, QStringList argument=QStringList())
ProcessWrapper(QString name="executable", QObject *parent=NULL)
qint64 write(const char *data)
bool waitForStarted(int msecs=30000)
bool waitForFinished(int msecs=30000)
virtual ~ProcessWrapper()
boost::shared_ptr< class ProcessReporter > ProcessReporterPtr
static QString getBundlePath()
return the folder where the bundle or executable are located.