24 QObject(parent), mName(name), mLastExecutablePath(
"")
26 mProcess =
new QProcess(
this);
29 mProcess->setProcessChannelMode(QProcess::MergedChannels);
30 mProcess->setReadChannel(QProcess::StandardOutput);
37 mProcess->terminate();
43 return mProcess.data();
48 QString absolutePathToExe = this->getExecutableInBundlesAbsolutePath(executable);
50 this->
launch(absolutePathToExe, arguments);
55 if (executable.isEmpty() || this->
isRunning())
58 this->internalLaunch(executable, arguments);
63 return mProcess->state() == QProcess::Running;
68 return mProcess->write(data);
73 return mProcess->waitForStarted(msecs);
78 return mProcess->waitForFinished(msecs);
81 QString ProcessWrapper::getExecutableInBundlesAbsolutePath(QString exeInBundle)
83 QString absolutePathToExe = exeInBundle;
85 if (!QFileInfo(absolutePathToExe).isAbsolute())
88 absolutePathToExe = absolutePathToExe.trimmed();
89 absolutePathToExe = QDir::cleanPath(absolutePathToExe);
91 if (!QFileInfo(absolutePathToExe).exists())
92 reportError(QString(
"Cannot find %1 [%2]").arg(mName).arg(absolutePathToExe));
94 return absolutePathToExe;
97 void ProcessWrapper::internalLaunch(QString executable, QStringList arguments)
102 report(QString(
"Launching %1: [%2 %3]").arg(mName).arg(executable).arg(arguments.join(
" ")));
104 if(arguments.isEmpty())
105 mProcess->start(executable);
107 mProcess->start(executable, arguments);
109 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.
Namespace for all CustusX production code.