QHash<QString, QString> KernelModel::getInstalledPackages() const { QProcess process; process.setEnvironment( QStringList() << "LANG=C" << "LC_MESSAGES=C" ); process.start( "pacman", QStringList() << "-Qs" << "^linux[0-9][0-9]?([0-9])" ); if ( !process.waitForFinished( 15000 ) ) qDebug() << "error: failed to get all installed kernels"; QString result = process.readAll(); QHash<QString, QString> packages; for ( QString line : result.split( "\n", QString::SkipEmptyParts ) ) { if ( line.isEmpty() ) continue; if ( line[0].isSpace() ) continue; QStringList parts = line.split( ' ' ); QString repoName = parts.value( 0 ); int a = repoName.indexOf( "/" ); QString pkgName = repoName.mid( a+1 ); QString pkgVersion = parts.value( 1 ); packages.insert( pkgName, pkgVersion ); } return packages; }
QProcess * Engine::run(QFileInfo input, QObject * parent /* = nullptr */) { QString exeFilePath = programPath(program()); if (exeFilePath.isEmpty()) return nullptr; QStringList env = QProcess::systemEnvironment(); QProcess * process = new QProcess(parent); QString workingDir = input.canonicalPath(); #if defined(Q_OS_WIN) // files in the root directory of the current drive have to be handled specially // because QFileInfo::canonicalPath() returns a path without trailing slash // (i.e., a bare drive letter) if (workingDir.length() == 2 && workingDir.endsWith(QChar::fromLatin1(':'))) workingDir.append(QChar::fromLatin1('/')); #endif process->setWorkingDirectory(workingDir); #if !defined(Q_OS_DARWIN) // not supported on OS X yet :( // Add a (customized) TEXEDIT environment variable env << QString::fromLatin1("TEXEDIT=%1 --position=%d %s").arg(QCoreApplication::applicationFilePath()); #if defined(Q_OS_WIN) // MiKTeX apparently uses it's own variable env << QString::fromLatin1("MIKTEX_EDITOR=%1 --position=%l \"%f\"").arg(QCoreApplication::applicationFilePath()); #endif #endif QStringList args = arguments(); #if !defined(MIKTEX) // for old MikTeX versions: delete $synctexoption if it causes an error static bool checkedForSynctex = false; static bool synctexSupported = true; if (!checkedForSynctex) { QString pdftex = programPath(QString::fromLatin1("pdftex")); if (!pdftex.isEmpty()) { int result = QProcess::execute(pdftex, QStringList() << QString::fromLatin1("-synctex=1") << QString::fromLatin1("-version")); synctexSupported = (result == 0); } checkedForSynctex = true; } if (!synctexSupported) args.removeAll(QString::fromLatin1("$synctexoption")); #endif args.replaceInStrings(QString::fromLatin1("$synctexoption"), QString::fromLatin1("-synctex=1")); args.replaceInStrings(QString::fromLatin1("$fullname"), input.fileName()); args.replaceInStrings(QString::fromLatin1("$basename"), input.completeBaseName()); args.replaceInStrings(QString::fromLatin1("$suffix"), input.suffix()); args.replaceInStrings(QString::fromLatin1("$directory"), input.absoluteDir().absolutePath()); process->setEnvironment(env); process->setProcessChannelMode(QProcess::MergedChannels); process->start(exeFilePath, args); return process; }
bool TestCompiler::runCommand( QString cmdline ) { testOutput_.append("Running command: " + cmdline); QProcess child; if (!environment_.empty()) child.setEnvironment(QProcess::systemEnvironment() + environment_); child.start(cmdline); if (!child.waitForStarted(-1)) { testOutput_.append( "Unable to start child process." ); return false; } bool failed = false; child.setReadChannel(QProcess::StandardError); child.waitForFinished(-1); foreach (const QByteArray &output, child.readAllStandardError().split('\n')) { testOutput_.append(QString::fromLocal8Bit(output)); if (output.startsWith("Project MESSAGE: FAILED")) failed = true; } return !failed && child.exitStatus() == QProcess::NormalExit && child.exitCode() == 0; }
DeviceList DeviceInfo::alsaDevices() { qDebug("DeviceInfo::alsaDevices"); DeviceList l; QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):"); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QStringList() << "LC_ALL=C"); p.start("aplay", QStringList() << "-l"); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine(); qDebug("DeviceInfo::alsaDevices: '%s'", line.constData()); if (rx_device.indexIn(line) > -1) { QString id = rx_device.cap(1); id.append("."); id.append(rx_device.cap(3)); QString desc = rx_device.cap(2); qDebug("DeviceInfo::alsaDevices: found device: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData()); l.append(DeviceData(id, desc)); } } } else { qDebug("DeviceInfo::alsaDevices: could not start aplay, error %d", p.error()); } return l; }
DeviceList DeviceInfo::xvAdaptors() { qDebug("DeviceInfo::xvAdaptors"); DeviceList l; QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\""); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C"); p.start("xvinfo"); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine(); qDebug("DeviceInfo::xvAdaptors: '%s'", line.constData()); if (rx_device.indexIn(line) > -1) { QString id = rx_device.cap(1); QString desc = rx_device.cap(2); qDebug("DeviceInfo::xvAdaptors: found adaptor: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData()); l.append(DeviceData(id, desc)); } } } else { qDebug("DeviceInfo::xvAdaptors: could not start xvinfo, error %d", p.error()); } return l; }
QProcess *QgsContextHelp::start() { // Get the path to the help viewer QString helpPath = QgsApplication::helpAppPath(); QgsDebugMsg( QString( "Help path is %1" ).arg( helpPath ) ); QProcess *process = new QProcess; // Delete this object if the process terminates connect( process, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( processExited() ) ); // Delete the process if the application quits connect( qApp, SIGNAL( aboutToQuit() ), process, SLOT( terminate() ) ); connect( process, SIGNAL( error( QProcess::ProcessError ) ), this, SLOT( error( QProcess::ProcessError ) ) ); #ifdef Q_OS_WIN if ( QgsApplication::isRunningFromBuildDir() ) { process->setEnvironment( QStringList() << QString( "PATH=%1;%2" ).arg( getenv( "PATH" ) ).arg( QApplication::applicationDirPath() ) ); } #endif process->start( helpPath, QStringList() ); return process; }
TDeviceList TDeviceInfo::alsaDevices() { Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo"); logger->debug("alsaDevices"); TDeviceList l; QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):"); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QStringList() << "LC_ALL=C"); p.start("aplay", QStringList() << "-l"); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine().trimmed(); if (rx_device.indexIn(line) >= 0) { QString id = rx_device.cap(1); id.append("."); id.append(rx_device.cap(3)); QString desc = rx_device.cap(2); logger->debug("alsaDevices: found device: '%1' '%2'", id, desc); l.append(TDeviceData(id, desc)); } } } else { logger->warn("alsaDevices: could not start aplay, error %1", p.error()); } return l; }
QString getGSLinuxPath( QString apps ) { QStringList potential_paths; potential_paths.append("/usr/local/bin"); potential_paths.append("/sw/bin"); /* to use on mac as same */ potential_paths.append("/opt/bin"); QProcess *process = new QProcess(NULL); process->setReadChannelMode(QProcess::MergedChannels); QStringList env = process->systemEnvironment(); env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+potential_paths.join(";")); process->setEnvironment(env); process->start( QString("which") , QStringList() << apps , QIODevice::ReadOnly ); if (!process->waitForFinished()) { return QString(); } else { QString finder = process->readAll().trimmed(); if (finder.endsWith(apps,Qt::CaseInsensitive)) { ///////////// qDebug() << "### finder " << finder; return finder; } else { return QString(); } } }
bool MountManager::mount() { if(!isPasswordCorrect()){ return false; } if(mountedDirExists()){ emit errorString(QString(QLatin1String("Already have something mounted in %1 ...continue")).arg(m_mountdir)); return true; } if(!QFileInfo(m_imgdir).exists()){ emit errorString(m_imgdir+QLatin1String("file does not exists\n")); return false; } QProcess proc; proc.setEnvironment(QProcess::systemEnvironment()); proc.start(QString(QLatin1String("sh -c \"echo %1 | sudo -S mount -o loop %2 %3\"")).arg(m_userPassWord).arg(m_imgdir).arg(m_mountdir)); if(!proc.waitForFinished()){ emit errorString(QString(QLatin1String("Can't mount image %1")).arg(QString(proc.errorString()))); return false; } if(!mountedDirExists()){ proc.waitForReadyRead(); emit errorString(QLatin1String(proc.readAllStandardError())); return false; } proc.terminate(); messageString(QString(QLatin1String("Image mounted in %1")).arg(m_mountdir)); return true; }
static bool runWithQtInEnvironment(const QString &cmd) { QProcess proc; // prepend the qt binary directory to the path QStringList env = QProcess::systemEnvironment(); for (int i=0; i<env.count(); ++i) { QString var = env.at(i); int setidx = var.indexOf(QLatin1Char('=')); if (setidx != -1) { QString varname = var.left(setidx).trimmed().toUpper(); if (varname == QLatin1String("PATH")) { var = var.mid(setidx + 1); var = QLatin1String("PATH=") + QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1Char(';') + var; env[i] = var; break; } } } proc.setEnvironment(env); proc.start(cmd); proc.waitForFinished(-1); return (proc.exitCode() == 0); }
TDeviceList TDeviceInfo::xvAdaptors() { Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo"); logger->debug("xvAdaptors"); TDeviceList l; QRegExp rx_device("^Adaptor #([0-9]+): \"(.*)\""); QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C"); p.start("xvinfo"); if (p.waitForFinished()) { while (p.canReadLine()) { QString s = QString::fromLocal8Bit(p.readLine()).trimmed(); logger->trace("xvAdaptors: line '%1'", s); if (rx_device.indexIn(s) >= 0) { QString id = rx_device.cap(1); QString desc = rx_device.cap(2); logger->debug("xvAdaptors: found adaptor: '" + id + " '" + desc + "'"); l.append(TDeviceData(id, desc)); } } } else { logger->warn("xvAdaptors: could not start xvinfo, error %1", p.error()); } return l; }
bool TestCompiler::runCommand( QString cmdline ) { testOutput_.append("Running command: " + cmdline); QProcess child; if (!environment_.empty()) child.setEnvironment(QProcess::systemEnvironment() + environment_); child.start(cmdline); if (!child.waitForStarted(-1)) { testOutput_.append( "Unable to start child process." ); return false; } bool failed = false; child.setReadChannel(QProcess::StandardError); while (QProcess::Running == child.state()) { if (child.waitForReadyRead(1000)) { QString output = child.readAllStandardError(); testOutput_.append(output); output.prepend('\n'); if (output.contains("\nProject MESSAGE: FAILED")) failed = true; } } child.waitForFinished(-1); return failed ? false : (child.exitStatus() == QProcess::NormalExit) && (child.exitCode() == 0); }
bool UiCodeModelSupport::runUic(const QString &ui) const { QProcess process; const QString uic = uicCommand(); process.setEnvironment(environment()); if (debug) qDebug() << "UiCodeModelSupport::runUic " << uic << " on " << ui.size() << " bytes"; process.start(uic, QStringList(), QIODevice::ReadWrite); if (!process.waitForStarted()) return false; process.write(ui.toUtf8()); process.closeWriteChannel(); if (process.waitForFinished() && process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0) { m_contents = process.readAllStandardOutput(); m_cacheTime = QDateTime::currentDateTime(); if (debug) qDebug() << "ok" << m_contents.size() << "bytes."; return true; } else { if (debug) qDebug() << "failed" << process.readAllStandardError(); process.kill(); } return false; }
void DlvDebugger::stepOut() { QString cmd = LiteApi::getGotools(m_liteApp); QProcess process; process.setEnvironment(LiteApi::getCurrentEnvironment(m_liteApp).toStringList()); QFileInfo info(m_lastFileName); process.setWorkingDirectory(info.path()); QStringList args; args << "finddecl" << "-file" << info.fileName() << "-line" << QString("%1").arg(m_lastFileLine+1); process.start(cmd,args); if (!process.waitForFinished(3000)) { emit debugLog(LiteApi::DebugErrorLog,"error wait find decl process"); process.kill(); return; } if (process.exitCode() != 0) { emit debugLog(LiteApi::DebugErrorLog,"error get find decl result"); return; } QByteArray data = process.readAll().trimmed(); QStringList ar = QString::fromUtf8(data).split(" "); if (ar.size() != 4 || ar[0] != "func") { emit debugLog(LiteApi::DebugErrorLog,"error find func decl in line"); return; } m_funcDecl.fileName = m_lastFileName; m_funcDecl.funcName = ar[1]; m_funcDecl.start = ar[2].toInt()-1; m_funcDecl.end = ar[3].toInt()-1; m_checkFuncDecl = true; command("next"); }
void ImportThread::run() { QProcess compileProcess; QString processBin = QString(); if ((Preferences::p_getCompiler()=="latex")||(Preferences::p_getCompiler()=="tex")) { processBin=Preferences::p_getLtx2pdf(); } else processBin=Preferences::p_getBin(Preferences::p_getCompiler()); #ifndef Q_OS_WIN QStringList env = QProcess::systemEnvironment(); int j = env.indexOf(QRegExp("^PATH=(.*)")); int limit = env.at(j).indexOf("="); QString value = env.at(j).right(env.at(j).size()-limit-1).trimmed(); value = "PATH=" + value + ":" + QFileInfo(processBin).path() + ":" + QFileInfo(Preferences::p_getBin("latex")).path() + ":" + QFileInfo(Preferences::p_getBin("dvips")).path() + ":" + QFileInfo(Preferences::p_getBin("ps2pdf")).path(); env.replace(j,value); compileProcess.setEnvironment(env); #endif int listLen = fileList.size(); QString exoFile; QMap<QString,QString> * exoMap = new QMap<QString,QString>; for (int i=0; i<listLen; i++) { exoMap = new QMap<QString,QString>; *exoMap = fileList.at(i); exoFile = exoMap->value("filepath"); compileProcess.setWorkingDirectory(QFileInfo(exoFile).path()); QStringList args; QString tmpFileName = QFileInfo(exoFile).baseName() + "-preview.tex"; if ((Preferences::p_getCompiler()=="latex")||(Preferences::p_getCompiler()=="tex")) { #ifdef Q_OS_WIN args << QFileInfo(exoFile).baseName() + "-preview" << Preferences::p_getBin("latex") << Preferences::p_getBin("dvips") << Preferences::p_getBin("ps2pdf") << Preferences::p_getCompilationOptions(); #else args << "-c" << tmpFileName << Preferences::p_getBin("latex") << Preferences::p_getBin("dvips") << Preferences::p_getBin("ps2pdf") << Preferences::p_getCompilationOptions(); // args << "-c" << tmpFileName << "latex" << "dvips" << "ps2pdf" << Preferences::p_getCompilationOptions(); #endif } else args << Preferences::p_getCompilationOptions() << tmpFileName; // On exécute la compilation compileProcess.start(processBin,args); compileProcess.waitForFinished(-1); QString errorOutput = compileProcess.readAll(); QString outName=QString(); outName = QFileInfo(exoFile).path() + QDir::separator()+ QFileInfo(exoFile).baseName()+"-preview.pdf"; QFile outFile; if (outFile.exists(outName)) { emit exoTreated(exoMap); } else emit errorOccured(exoFile,errorOutput); exoMap->~QMap(); } }
bool BuildableHelperLibrary::buildHelper(const BuildHelperArguments &arguments, QString *log, QString *errorMessage) { const QChar newline = QLatin1Char('\n'); // Setup process QProcess proc; proc.setEnvironment(arguments.environment.toStringList()); proc.setWorkingDirectory(arguments.directory); proc.setProcessChannelMode(QProcess::MergedChannels); log->append(QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "Building helper \"%1\" in %2\n").arg(arguments.helperName, arguments.directory)); log->append(newline); const FileName makeFullPath = arguments.environment.searchInPath(arguments.makeCommand); if (QFileInfo::exists(arguments.directory + QLatin1String("/Makefile"))) { if (makeFullPath.isEmpty()) { *errorMessage = QCoreApplication::translate("ProjectExplorer::DebuggingHelperLibrary", "%1 not found in PATH\n").arg(arguments.makeCommand); return false; } const QString cleanTarget = QLatin1String("distclean"); log->append(QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "Running %1 %2...\n") .arg(makeFullPath.toUserOutput(), cleanTarget)); if (!runBuildProcess(proc, makeFullPath, QStringList(cleanTarget), 30, true, log, errorMessage)) return false; } QStringList qmakeArgs; if (!arguments.targetMode.isEmpty()) qmakeArgs << arguments.targetMode; if (!arguments.mkspec.isEmpty()) qmakeArgs << QLatin1String("-spec") << arguments.mkspec.toUserOutput(); qmakeArgs << arguments.proFilename; qmakeArgs << arguments.qmakeArguments; log->append(newline); log->append(QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "Running %1 %2 ...\n").arg(arguments.qmakeCommand.toUserOutput(), qmakeArgs.join(QLatin1Char(' ')))); if (!runBuildProcess(proc, arguments.qmakeCommand, qmakeArgs, 30, false, log, errorMessage)) return false; log->append(newline); if (makeFullPath.isEmpty()) { *errorMessage = QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "%1 not found in PATH\n").arg(arguments.makeCommand); return false; } log->append(QCoreApplication::translate("ProjectExplorer::BuildableHelperLibrary", "Running %1 %2 ...\n") .arg(makeFullPath.toUserOutput(), arguments.makeArguments.join(QLatin1Char(' ')))); if (!runBuildProcess(proc, makeFullPath, arguments.makeArguments, 120, false, log, errorMessage)) return false; return true; }
void startProcess() { //! [0] QProcess process; QStringList env = QProcess::systemEnvironment(); env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;C:\\Bin"); process.setEnvironment(env); process.start("myapp"); //! [0] }
/*! Executes a command as a process Output written to given socket as response. */ void ShellCommandService::detachedShellCommand(QString message, TasResponse& response) { TasLogger::logger()->debug("ShellCommandService::detachedShellCommand: " + message); QProcess process; process.setReadChannelMode(QProcess::MergedChannels); process.setEnvironment(QProcess::systemEnvironment()); bool started = process.startDetached(message); if(!started){ response.setErrorMessage("Failed to start process!"); } }
void Decompile::run() { // Arguments QStringList arguments; arguments << QString("-Xms").append(QString::number(Utility::Configuration::heap())).append("m"); arguments << QString("-jar"); arguments << Utility::Configuration::apktool(); arguments << QString("--force"); if (!this->_tag.isEmpty()) { arguments << QString("--frame-path"); arguments << Utility::Configuration::framework(); arguments << QString("--frame-tag"); arguments << QString(this->_tag); } if (Utility::Configuration::verbose()) arguments << QString("--verbose"); arguments << QString("--output"); arguments << QString(this->_location); arguments << QString("d"); arguments << QString(this->_apk); // Process QProcess process; process.setEnvironment(QProcess::systemEnvironment()); process.setProcessChannelMode(QProcess::MergedChannels); // Start process.start(QString("java"), arguments, QIODevice::ReadOnly); // Wait (Start) if (!process.waitForStarted()) { emit newStatusInfo(this->_apk, QString()); } // Wait (Read) process.waitForReadyRead(-1); // Wait (Stop) process.waitForFinished(-1); QString decomOutput(process.readAllStandardOutput()); emit Decompile::newInfo(decomOutput); // Verify QString yml = QString(this->_location).append("/apktool.yml"); QFileInfo info(yml); if (!info.exists() || !info.isFile()) { // Read QString output = process.readAll(); emit Decompile::output(output); emit newStatusInfo(this->_apk, QString()); return; } else // Broadcast emit newStatusInfo(this->_apk, info.absoluteFilePath()); }
bool KeyBoardPreview::loadCodes() { if (layout.isEmpty()) return false; QStringList param; param << "-model" << "pc106" << "-layout" << layout << "-compact"; if (!variant.isEmpty()) param << "-variant" << variant; QProcess process; process.setEnvironment(QStringList() << "LANG=C" << "LC_MESSAGES=C"); process.start("ckbcomp", param); if (!process.waitForStarted()) return false; if (!process.waitForFinished()) return false; // Clear codes codes.clear(); const QStringList list = QString(process.readAll()).split("\n", QString::SkipEmptyParts); for (const QString &line : list) { if (!line.startsWith("keycode") || !line.contains('=')) continue; QStringList split = line.split('=').at(1).trimmed().split(' '); if (split.size() < 4) continue; Code code; code.plain = fromUnicodeString(split.at(0)); code.shift = fromUnicodeString(split.at(1)); code.ctrl = fromUnicodeString(split.at(2)); code.alt = fromUnicodeString(split.at(3)); if (code.ctrl == code.plain) code.ctrl = ""; if (code.alt == code.plain) code.alt = ""; codes.append(code); } return true; }
bool MaemoGlobal::callMaddeShellScript(QProcess &proc, const QString &qmakePath, const QString &command, const QStringList &args, bool useTarget) { if (!QFileInfo(command).exists()) return false; QString actualCommand = command; QStringList actualArgs = targetArgs(qmakePath, useTarget) + args; Environment env(proc.systemEnvironment()); addMaddeEnvironment(env, qmakePath); proc.setEnvironment(env.toStringList()); transformMaddeCall(actualCommand, actualArgs, qmakePath); proc.start(actualCommand, actualArgs); return true; }
/*! Executes a command as a process Output written to given socket as response. */ void ShellCommandService::shellCommand(QString message, TasResponse& response) { TasLogger::logger()->debug("ShellCommandService::shellCommand: " + message); QProcess process; process.setReadChannelMode(QProcess::MergedChannels); process.setEnvironment(QProcess::systemEnvironment()); process.start(message); process.closeWriteChannel(); process.waitForFinished(4000); QByteArray output = process.readAll(); response.setData(output); }
void MainWindow::bash(QString command) { QProcess *p = new QProcess( this ); if (p) { p->setEnvironment( QProcess::systemEnvironment() ); p->setProcessChannelMode( QProcess::MergedChannels ); p->start( command ); p->waitForStarted(); connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) ); connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) ); } }
bool SslCertificate::runTool(const QStringList& args) { QString program; #if defined(Q_OS_WIN) program = QCoreApplication::applicationDirPath(); program.append("\\").append(kWinOpenSslBinary); #else program = kUnixOpenSslCommand; #endif QStringList environment; #if defined(Q_OS_WIN) environment << QString("OPENSSL_CONF=%1\\%2") .arg(QCoreApplication::applicationDirPath()) .arg(kConfigFile); #endif QProcess process; process.setEnvironment(environment); process.start(program, args); bool success = process.waitForStarted(); QString standardError; if (success && process.waitForFinished()) { m_ToolOutput = process.readAllStandardOutput().trimmed(); standardError = process.readAllStandardError().trimmed(); } int code = process.exitCode(); if (!success || code != 0) { emit error( QString("SSL tool failed: %1\n\nCode: %2\nError: %3") .arg(program) .arg(process.exitCode()) .arg(standardError.isEmpty() ? "Unknown" : standardError)); return false; } return true; }
void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info, bool force) { if (info.qmlDumpPath.isEmpty() || info.qtImportsPath.isEmpty()) return; const QString importsPath = QDir::cleanPath(info.qtImportsPath); if (m_runningQmldumps.values().contains(importsPath)) return; LibraryInfo builtinInfo; if (!force) { const Snapshot snapshot = m_modelManager->snapshot(); builtinInfo = snapshot.libraryInfo(info.qtImportsPath); if (builtinInfo.isValid()) return; } builtinInfo = LibraryInfo(LibraryInfo::Found); m_modelManager->updateLibraryInfo(info.qtImportsPath, builtinInfo); // prefer QTDIR/imports/builtins.qmltypes if available const QString builtinQmltypesPath = info.qtImportsPath + QLatin1String("/builtins.qmltypes"); if (QFile::exists(builtinQmltypesPath)) { loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtImportsPath, builtinInfo); return; } // QTDIR/imports/QtQuick1/builtins.qmltypes was used in developer builds of 5.0.0, 5.0.1 const QString builtinQmltypesPath2 = info.qtImportsPath + QLatin1String("/QtQuick1/builtins.qmltypes"); if (QFile::exists(builtinQmltypesPath2)) { loadQmltypesFile(QStringList(builtinQmltypesPath2), info.qtImportsPath, builtinInfo); return; } // run qmldump QProcess *process = new QProcess(this); process->setEnvironment(info.qmlDumpEnvironment.toStringList()); connect(process, SIGNAL(finished(int)), SLOT(qmlPluginTypeDumpDone(int))); connect(process, SIGNAL(error(QProcess::ProcessError)), SLOT(qmlPluginTypeDumpError(QProcess::ProcessError))); QStringList args(QLatin1String("--builtins")); process->start(info.qmlDumpPath, args); m_runningQmldumps.insert(process, info.qtImportsPath); m_qtToInfo.insert(info.qtImportsPath, info); }
QList<DiskDevice * > enumerateDevice() { updateKernelTable(); QList<DiskDevice *> devices; utils::writeLog("Enumerating imageable devices for Linux"); QProcess process; QStringList lines; //process.start("/usr/bin/gksudo", QStringList() << "/sbin/fdisk -l", QIODevice::ReadWrite | QIODevice::Text); /* To run in Qt */ process.setEnvironment(QStringList() << "LANG=C"); process.start("/sbin/fdisk", QStringList() << "-l", QIODevice::ReadOnly | QIODevice::Text); if (! process.waitForFinished()) utils::writeLog("Could not execute fdisk to enumerate devices"); else { QTextStream stdoutStream(process.readAllStandardOutput()); while (true) { QString line = stdoutStream.readLine(); if (line.isNull()) break; else lines << line << "\n"; } for (int i = 0; i < lines.count(); i++) { QString line = lines.at(i); if (line.startsWith("Disk /dev") && ! (line.startsWith("Disk /dev/sda") || line.startsWith("Disk /dev/hda") || line.startsWith("Disk /dev/xvda"))) { QStringList deviceAttr = line.split(" "); QString devicePath; QString deviceSpace; devicePath = deviceAttr.at(1); devicePath.remove(":"); deviceSpace = deviceAttr.at(2) + deviceAttr.at(3); deviceSpace.remove(","); DiskDevice *nd = new DiskDevice(i, devicePath, deviceSpace); devices.append(nd); } } } return devices; }
static QString getOperatingSystem() { #if defined (Q_OS_WIN32) switch(QSysInfo::windowsVersion()) { case QSysInfo::WV_NT: return QString::fromAscii("Windows NT"); case QSysInfo::WV_2000: return QString::fromAscii("Windows 2000"); case QSysInfo::WV_XP: return QString::fromAscii("Windows XP"); case QSysInfo::WV_2003: return QString::fromAscii("Windows Server 2003"); case QSysInfo::WV_VISTA: return QString::fromAscii("Windows Vista"); case QSysInfo::WV_WINDOWS7: return QString::fromAscii("Windows 7"); default: return QString::fromAscii("Windows"); } #elif defined (Q_OS_MAC) return QString::fromAscii("Mac OS X"); #elif defined (Q_OS_LINUX) QString exe(QLatin1String("lsb_release")); QStringList args; args << QLatin1String("-ds"); QProcess proc; proc.setEnvironment(QProcess::systemEnvironment()); proc.start(exe, args); if (proc.waitForStarted() && proc.waitForFinished()) { QByteArray info = proc.readAll(); info.replace('\n',""); return QString::fromAscii((const char*)info); } return QString::fromAscii("Linux"); #elif defined (Q_OS_UNIX) return QString::fromAscii("UNIX"); #else return QString(); #endif }
GdbCoreEngine::CoreInfo GdbCoreEngine::readExecutableNameFromCore(const QString &debuggerCommand, const QString &coreFile) { CoreInfo cinfo; #if 0 ElfReader reader(coreFile); cinfo.isCore = false; cinfo.rawStringFromCore = QString::fromLocal8Bit(reader.readCoreName(&cinfo.isCore)); cinfo.foundExecutableName = findExecutableFromName(cinfo.rawStringFromCore, coreFile); #else QStringList args; args.append(QLatin1String("-nx")); args.append(QLatin1String("-batch")); args.append(QLatin1String("-c")); args.append(coreFile); QProcess proc; QStringList envLang = QProcess::systemEnvironment(); envLang.replaceInStrings(QRegExp(QLatin1String("^LC_ALL=.*")), QLatin1String("LC_ALL=C")); proc.setEnvironment(envLang); proc.start(debuggerCommand, args); if (proc.waitForFinished()) { QByteArray ba = proc.readAllStandardOutput(); // Core was generated by `/data/dev/creator-2.6/bin/qtcreator'. // Program terminated with signal 11, Segmentation fault. int pos1 = ba.indexOf("Core was generated by"); if (pos1 != -1) { pos1 += 23; int pos2 = ba.indexOf('\'', pos1); if (pos2 != -1) { cinfo.isCore = true; cinfo.rawStringFromCore = QString::fromLocal8Bit(ba.mid(pos1, pos2 - pos1)); cinfo.foundExecutableName = findExecutableFromName(cinfo.rawStringFromCore, coreFile); } } } cinfo.isCore = false; #endif return cinfo; }
PackageInfo UpdateProcess::packageInfo(const QString &package) { QProcess proc; QStringList args; args << "json2xml" << QDir::convertSeparators(updateRepositoryDir() + "/" + package); vNotice("updater: launching auto-update executable: %1 %2") .arg(updateExecutable()) .arg(args.join(" ")); proc.setEnvironment(proc.systemEnvironment()); proc.start(updateExecutable(), args); if (! proc.waitForStarted()) return PackageInfo(); if (! proc.waitForFinished()) return PackageInfo(); return packageInfoFromXml(proc.readAll()); }
bool BlastSearch::findProgram(QString programName, QString * command) { QString findCommand = "which " + programName; #ifdef Q_OS_WIN32 findCommand = "WHERE " + programName; #endif QProcess find; //On Mac, it's necessary to do some stuff with the PATH variable in order //for which to work. #ifdef Q_OS_MAC QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QStringList envlist = env.toStringList(); //Add some paths to the process environment envlist.replaceInStrings(QRegularExpression("^(?i)PATH=(.*)"), "PATH=" "/usr/bin:" "/bin:" "/usr/sbin:" "/sbin:" "/opt/local/bin:" "/usr/local/bin:" "$HOME/bin:" "/usr/local/ncbi/blast/bin:" "\\1"); find.setEnvironment(envlist); #endif find.start(findCommand); find.waitForFinished(); //On a Mac, we need to use the full path to the program. #ifdef Q_OS_MAC *command = QString(find.readAll()).simplified(); #endif return (find.exitCode() == 0); }