GdbProcess(const QString &program) : QProcess() { setProcessChannelMode(MergedChannels); // don't attempt to load .gdbinit in home (may cause unexpected results) QProcess::start("gdb", (QStringList() << "-nx" << (BINARY_PATH + '/' + program))); const bool started = waitForStarted(); if (!started) { qDebug() << "Failed to start 'gdb' executable:" << errorString(); Q_ASSERT(false); return; } QByteArray prompt = waitForPrompt(); QVERIFY(!prompt.contains("No such file or directory")); execute("set confirm off"); execute("set print pretty on"); execute("set disable-randomization off"); // see https://phabricator.kde.org/D2188 QList<QByteArray> p; QDir printersDir = QFileInfo(__FILE__).dir(); printersDir.cdUp(); // go up to get to the main printers directory p << "python" << "import sys" << "sys.path.insert(0, '"+printersDir.path().toLatin1()+"')" << "from qt import register_qt_printers" << "register_qt_printers (None)" << "from kde import register_kde_printers" << "register_kde_printers (None)" << "end"; foreach (const QByteArray &i, p) { write(i + "\n"); }
bool Kleo::SymCryptRunProcessBase::launch( const QByteArray & input, bool block ) { connect( this, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadyReadStandardOutput()) ); connect( this, SIGNAL(readyReadStandardError()), this, SLOT(slotReadyReadStandardError()) ); if ( block ) { KTemporaryFile tempfile; if ( tempfile.open() ) tempfile.write( input ); else return false; tempfile.flush(); *this << "--input" << tempfile.fileName(); addOptions(); if(KProcess::execute() == -2) return false; } else { addOptions(); KProcess::start(); const bool ok = waitForStarted(); if ( !ok ) return ok; mInput = input; write( mInput ); closeWriteChannel(); } return true; }
bool DebuggerDriver::startup(QString cmdStr) { // clear command queues delete m_activeCmd; m_activeCmd = 0; flushHiPriQueue(); flushLoPriQueue(); m_state = DSidle; // debugger executable if (cmdStr.isEmpty()) cmdStr = defaultInvocation(); QStringList cmd = cmdStr.split(' ', QString::SkipEmptyParts); if (cmd.isEmpty()) return false; QString pgm = cmd.takeFirst(); setProcessChannelMode(MergedChannels); start(pgm, cmd); if (!waitForStarted(-1)) return false; // open log file if (!m_logFile.isOpen() && !m_logFileName.isEmpty()) { m_logFile.setFileName(m_logFileName); m_logFile.open(QIODevice::WriteOnly); } return true; }
bool MPlayerProcess::start(const QStringList & arguments, const QString & filename, WId videoWidgetId, qint64 seek) { //Stop MPlayerProcess if it is already running if (isRunning()) { stop(); } init(); QStringList args; args << arguments; if (videoWidgetId > 0) { //Attach MPlayer video output to our widget _mediaData.videoWidgetId = videoWidgetId; args << "-wid"; args << QString::number((qint64) _mediaData.videoWidgetId); } //If seek < 5 it's better to allow the video to start from the beginning if (seek > 5) { _mediaData.currentTime = seek; args << "-ss"; args << QString::number(_mediaData.currentTime / SECONDS_CONVERTION); } //File to play _mediaData.filename = filename; args << filename; MyProcess::start(MPLAYER_EXE, args); return waitForStarted(); }
/*! * \brief Translates text on not Linux paltforms. */ QString Translator::notLinuxTranslate(QString text) { QString name = parent->getCurrentSourceLang() + "-" + parent->getCurrentTargetLang(); if (name.isEmpty()) return ""; QDir dir(QDir(DATALOCATION).absoluteFilePath("usr/share/apertium/modes")); if (!dir.exists() || !dir.exists(name + ".mode")) return ""; QFile file(dir.absoluteFilePath(name + ".mode")); if (file.open(QIODevice::ReadOnly) == false) { return ""; } QString mode = file.readAll(); file.close(); mode = mode.trimmed(); if (mode.isEmpty()) { return ""; } mode.replace("$1", "-g"); mode.remove("$2"); if (mode.indexOf("'/usr/share") == -1) { mode.replace(QRegularExpression("(\\s*)(/usr/share/\\S+)(\\s*)"), "\\1\"\\2\"\\3"); } mode.replace("/usr/share", QDir(DATALOCATION).absolutePath() + "/usr/share"); #ifdef Q_OS_WIN // Windows can't handle C:/ paths in ' quotes mode.replace("'", "\""); #define OS_SEP ";" #else #define OS_SEP ":" #endif auto env = QProcessEnvironment::systemEnvironment(); env.insert("PATH", QDir(DATALOCATION).absoluteFilePath("apertium-all-dev/bin") + OS_SEP + env.value("PATH")); env.insert("LC_ALL", "en_US.UTF-8"); auto run = new QProcess(this); run->setProcessEnvironment(env); run->setProcessChannelMode(QProcess::MergedChannels); #ifdef Q_OS_WIN run->setNativeArguments(mode); run->start("cmd", QStringList() << "/D" << "/Q" << "/S" << "/C"); #else run->start("/bin/sh", QStringList() << "-c" << mode); #endif run->waitForStarted(); run->write(text.toUtf8() + " "); run->closeWriteChannel(); run->waitForFinished(); run->deleteLater(); return QString::fromUtf8(run->readAll()); }
VisualizerProcess(char *logd) : QProcess() { setReadChannelMode(QProcess::ForwardedChannels); //setStandardOutputFile("vis.out"); start(logd); waitForStarted(); QTime timer; timer.start(); while(timer.elapsed() < 1000); }
bool UserSession::start() { QProcessEnvironment env = qobject_cast<HelperApp*>(parent())->session()->processEnvironment(); if (env.value("XDG_SESSION_CLASS") == "greeter") QProcess::start(m_path); else { QStringList args; args << m_path; QProcess::start(SESSION_COMMAND, {args}); } return waitForStarted(); }
void CommandProcess::init() { #if defined(Q_OS_WIN) // Starting MS-DOS start(WINDOWS_CMD_PROCESS); #endif #if defined(Q_OS_UNIX) start(UNIX_CMD_PROCESS); #endif waitForStarted(); }
bool UserSession::start() { QProcessEnvironment env = qobject_cast<HelperApp*>(parent())->session()->processEnvironment(); if (env.value("XDG_SESSION_CLASS") == "greeter") QProcess::start(m_path); else { qDebug() << "Starting:" << mainConfig.XDisplay.SessionCommand.get() << m_path; QProcess::start(mainConfig.XDisplay.SessionCommand.get(), QStringList() << m_path); } return waitForStarted(); }
/** * Executes the back-end process. * @param sName The name of the process (for error messages) * @param slArgs A list containing the command-line arguments * @param sWorkDir (Optional) working directory * @param bBlock (Optional) true to block, false otherwise * @return true if the process was executed successfully, false otherwise */ bool Frontend::run(const QString& sName, const QStringList& slArgs, const QString& incDirs, const QString& srcDirs, const QString& sWorkDir, bool bBlock) { // Cannot start if another controlled process is currently running if (QProcess::state() == QProcess::Running) { m_sError = i18n("Cannot restart while another process is still " "running"); return false; } // Reset variables m_nRecords = 0; m_bKilled = false; // Setup the command-line arguments clearProgram(); if (m_bUseShell) // Execute inside a shell; join all arguments in a single QString setShellCommand(slArgs.join(" ")); else // Or setup args directly setProgram(slArgs); // Set the working directory, if requested if (!sWorkDir.isEmpty()) setWorkingDirectory(sWorkDir); // Set environment variables (INCLUDEDIRS & SOURCEDIRS) if required if (! incDirs.isEmpty()) { setEnv("INCLUDEDIRS", incDirs); } if (! srcDirs.isEmpty()) { setEnv("SOURCEDIRS", srcDirs); } // Execute the child process setOutputChannelMode( KProcess::SeparateChannels ); start(); if (! ( bBlock ? waitForFinished( -1 ) : waitForStarted ( -1 ))) { m_sError = sName + i18n(": Failed to start process"); return false; } m_sError = i18n("No error"); return true; }
bool KJavaProcess::invokeJVM() { QStringList args; if( !d->classPath.isEmpty() ) { args << "-classpath"; args << d->classPath; } //set the system properties, iterate through the qmap of system properties QMap<QString,QString>::ConstIterator it = d->systemProps.constBegin(); const QMap<QString,QString>::ConstIterator itEnd = d->systemProps.constEnd(); for( ; it != itEnd; ++it ) { if( !it.key().isEmpty() ) { QString currarg = "-D" + it.key(); if( !it.value().isEmpty() ) currarg += '=' + it.value(); args << currarg; } } //load the extra user-defined arguments if( !d->extraArgs.isEmpty() ) { KShell::Errors err; args += KShell::splitArgs( d->extraArgs, KShell::AbortOnMeta, &err ); if( err != KShell::NoError ) kWarning(6100) << "Extra args for JVM cannot be parsed, arguments = " << d->extraArgs; } args << d->mainClass; if ( !d->classArgs.isNull() ) args << d->classArgs; kDebug(6100) << "Invoking JVM" << d->jvmPath << "now...with arguments = " << KShell::joinArgs(args); setOutputChannelMode(KProcess::SeparateChannels); setProgram( d->jvmPath, args ); start(); return waitForStarted(); }
QString IpProcess::executeSynchronous(const QString &program, const QStringList &arguments) { QString empty(""); QString result(""); printCmdLine(program, arguments); if (arguments.count() > 0) { start(program, arguments); } else { start(program); } if (! waitForStarted()) return empty; closeWriteChannel(); int secondsToWait = 30; if (! waitForFinished(secondsToWait * 1000)) return empty; // exit code of zero means command completed ok // and that output is from stdout - error output is on stderrs if ( (exitCode() == 0) && (errStr.isEmpty()) ) { result = QString(QString(readAllStandardOutput())); } else { result = QString(QString(readAllStandardError())); } if (result.isEmpty()) { // result = parseErrorCode(); } // Send the result of executing the command emit cmdOutput(program, arguments, exitCode(), result); return QString(result); }
/*! Blocks until the process has finished and the finished() signal has been emitted, or until \a msecs milliseconds have passed. Returns true if the process finished; otherwise returns false (if the operation timed out or if an error occurred). This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread. \warning Calling this function from the main (GUI) thread might cause your user interface to freeze. If msecs is -1, this function will not time out. \sa finished(), waitForStarted(), waitForReadyRead(), waitForBytesWritten() */ bool QProcess::waitForFinished(int msecs) { Q_D(QProcess); if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { QTime stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) return false; if (msecs != -1) msecs -= stopWatch.elapsed(); } return d->waitForFinished(msecs); }
bool UserSession::start() { QProcessEnvironment env = qobject_cast<HelperApp*>(parent())->session()->processEnvironment(); if (env.value(QStringLiteral("XDG_SESSION_CLASS")) == QStringLiteral("greeter")) { QProcess::start(m_path); } else if (env.value(QStringLiteral("XDG_SESSION_TYPE")) == QStringLiteral("x11")) { qDebug() << "Starting:" << mainConfig.XDisplay.SessionCommand.get() << m_path; QProcess::start(mainConfig.XDisplay.SessionCommand.get(), QStringList() << m_path); } else if (env.value(QStringLiteral("XDG_SESSION_TYPE")) == QStringLiteral("wayland")) { qDebug() << "Starting:" << mainConfig.WaylandDisplay.SessionCommand.get() << m_path; QProcess::start(mainConfig.WaylandDisplay.SessionCommand.get(), QStringList() << m_path); } else { qCritical() << "Unable to run user session: unknown session type"; } return waitForStarted(); }
/*! *启动mplayer 进程 \param QString & fileName 要播放的资源名称 \param Media_Type type 媒体模式 \param int seek 从指定位置开始播放以秒为单位,当小于2时从头开始播放 */ bool IBMediaControlC::play( const QString & fileName, Media_Type type,int seek) { if( d->m_media_type != type ) { d->m_media_type = MEDIA_TYPE_NONE; } if(isRunning()) { /* if(fileName == d->m_s_current_media && d->m_current_play_state != MEDIA_RUNNING_STATE_STOP)//如果正在播放放当前的文件 { pause(); return true; }*/ stop(); } //获取媒体文件类型,并对视屏文件进行特别处理 //l_type = d->parseMediaTypeByName(fileName); if(d->m_media_type !=type) { d->m_media_type = type; emit sigMediaTypeChanged(type); } // if(type == MEDIA_TYPE_MOVIE) // { // if(!d->m_video_sreen_keeping) // { // d->initVideoFrameBuffer();//打开视屏文件时需要初始化 // } // else // d->m_video_sreen_keeping = false; // } //设置播放参数 QStringList args = getArglist(); //记忆上次的视屏播放模式 if(true == isFullScreenWindowMode()) { args<<"-fs"; } #ifdef _8925_VERSION if(seek >2) { QString str = QString::number(seek); args<<"-ss"; args<<str; } #endif /*QString s_equalizer =QString("-af"); args<<s_equalizer; s_equalizer= QString("equalizer=")+d->getEqualizerString(); args <<s_equalizer;*/ args << fileName; start(MPLAYER_PATH, args); bool res=waitForStarted(); //小于2s 从头播放 #ifndef _8925_VERSION if(seek >2) { sendCommand(QString("pausing_keep ")+QString("seek ") + QString::number(seek) +QString(" 2")); } #endif return res; }
bool ExportSpreadsheet::exportSpreadsheet(const analysisdriver::SimpleProject& project) { //Make sure a QApplication exists openstudio::Application::instance().application(); //get the project's directory openstudio::path projectPath = project.projectDir(); LOG_FREE(Debug, "ExportSpreadsheet", "Starting export of projectPath:" << toString(projectPath)); openstudio::path rubyPath; #if defined(Q_OS_WIN) rubyPath = getOpenStudioEmbeddedRubyPath() / toPath("bin/ruby.exe"); #else rubyPath = "ruby"; #endif openstudio::path rubyIncludePath = getOpenStudioRubyIncludePath(); if (!boost::filesystem::exists(rubyIncludePath)) { LOG_FREE(Error, "ExportSpreadsheet", "Ruby include path '" << rubyIncludePath << "' cannot be found."); return false; } openstudio::path scriptPath = getOpenStudioRubyScriptsPath() / openstudio::toPath("openstudio/analysisdriver/ExportToSpreadsheet.rb"); if (!boost::filesystem::exists(scriptPath)) { LOG_FREE(Error, "ExportSpreadsheet", "ExportToSpreadsheet script '" << scriptPath << "' cannot be found."); return false; } QStringList args; args << "-I"; args << openstudio::toQString(rubyIncludePath); args << openstudio::toQString(scriptPath); args << openstudio::toQString(projectPath); auto p = new QProcess(); p->start(toQString(rubyPath), args); if (!p->waitForStarted(30000)) { p->terminate(); p->deleteLater(); LOG_FREE(Error, "ExportSpreadsheet", "Process failed to start"); return false; } if (!p->waitForFinished(300000)) { p->terminate(); p->deleteLater(); LOG_FREE(Error, "ExportSpreadsheet", "Process failed to complete"); return false; } QByteArray error = p->readAllStandardError(); std::string errorString = toString(QString(error)); LOG_FREE(Debug, "ExportSpreadsheet", "StandardError:" << std::endl << errorString); QByteArray output = p->readAllStandardOutput(); std::string outputString = toString(QString(output)); LOG_FREE(Debug, "ExportSpreadsheet", "StandardOutput:" << std::endl << outputString); // remove previous export openstudio::path exportPath = projectPath / toPath("analysis_spreadsheet_export"); openstudio::path modelMeasuresCSV = exportPath / toPath("spreadsheet_model_measures_export.csv"); openstudio::path energyplusMeasuresCSV = exportPath / toPath("spreadsheet_energyplus_measures_export.csv"); openstudio::path reportingMeasuresCSV = exportPath / toPath("spreadsheet_reporting_measures_export.csv"); openstudio::path outputsCSV = exportPath / toPath("spreadsheet_outputs_export.csv"); bool result = ((p->exitStatus() == QProcess::NormalExit) && boost::filesystem::exists(modelMeasuresCSV) && boost::filesystem::exists(energyplusMeasuresCSV) && boost::filesystem::exists(reportingMeasuresCSV) && boost::filesystem::exists(outputsCSV)); p->deleteLater(); return result; }