Example #1
0
bool PuppetCreator::startBuildProcess(const QString &buildDirectoryPath,
                                      const QString &command,
                                      const QStringList &processArguments,
                                      PuppetBuildProgressDialog *progressDialog) const
{
    if (command.isEmpty())
        return false;

    QProcess process;
    process.setProcessChannelMode(QProcess::MergedChannels);
    process.setProcessEnvironment(processEnvironment());
    process.setWorkingDirectory(buildDirectoryPath);
    process.start(command, processArguments);
    process.waitForStarted();
    while (true) {
        if (process.waitForReadyRead(100)) {
            QByteArray newOutput = process.readAllStandardOutput();
            if (progressDialog)  {
                progressDialog->newBuildOutput(newOutput);
                m_compileLog.append(newOutput);
            }
        }

        if (process.state() == QProcess::NotRunning)
            break;
    }

    if (process.exitStatus() == QProcess::NormalExit || process.exitCode() == 0)
        return true;
    else
        return false;
}
Example #2
0
inline QStringList ProcessRun(QString cmd, QStringList args){
  //Assemble outputs
  QStringList out; out << "1" << ""; //error code, string output
  QProcess proc;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  proc.setProcessEnvironment(env);
  proc.setProcessChannelMode(QProcess::MergedChannels);
  if(args.isEmpty()){
    proc.start(cmd, QIODevice::ReadOnly);
  }else{
    proc.start(cmd,args ,QIODevice::ReadOnly);	  
  }
  QString info;
  while(!proc.waitForFinished(1000)){
    if(proc.state() == QProcess::NotRunning){ break; } //somehow missed the finished signal
    QString tmp = proc.readAllStandardOutput();
    if(tmp.isEmpty()){ proc.terminate(); }
    else{ info.append(tmp); }
  }
  out[0] = QString::number(proc.exitCode());
  out[1] = info+QString(proc.readAllStandardOutput());
  return out;	
}
// Note this functions is duplicated between AndroidDeployStep and AndroidDeployQtStep
// since it does modify the stored password in AndroidDeployQtStep it's not easily
// extractable. The situation will clean itself up once AndroidDeployStep is no longer
// necessary
QAbstractItemModel *AndroidDeployQtStep::keystoreCertificates()
{
    QString rawCerts;
    QProcess keytoolProc;
    while (!rawCerts.length() || !m_keystorePasswd.length()) {
        QStringList params;
        params << QLatin1String("-list") << QLatin1String("-v") << QLatin1String("-keystore") << m_keystorePath.toUserOutput() << QLatin1String("-storepass");
        if (!m_keystorePasswd.length())
            keystorePassword();
        if (!m_keystorePasswd.length())
            return 0;
        params << m_keystorePasswd;
        Utils::Environment env = Utils::Environment::systemEnvironment();
        env.set(QLatin1String("LANG"), QLatin1String("C"));
        keytoolProc.setProcessEnvironment(env.toProcessEnvironment());
        keytoolProc.start(AndroidConfigurations::instance().keytoolPath().toString(), params);
        if (!keytoolProc.waitForStarted() || !keytoolProc.waitForFinished()) {
            QMessageBox::critical(0, tr("Error"),
                                  tr("Failed to run keytool"));
            return 0;
        }

        if (keytoolProc.exitCode()) {
            QMessageBox::critical(0, tr("Error"),
                                  tr("Invalid password"));
            m_keystorePasswd.clear();
        }
        rawCerts = QString::fromLatin1(keytoolProc.readAllStandardOutput());
    }
    return new CertificatesModel(rawCerts, this);
}
// test connection
void SettingsDialog::on_testBtn_clicked()
{
    QString command = tr("ssh %1@%2 exit").arg(ui->serverUsernameLn->text(),
                                               ui->serverIpLn->text());

    QProcess *process = new QProcess(this);

    process->setProcessEnvironment(MainUtils::mainEnvironment());
    process->start(tr("/bin/bash -c \"%1\"").arg(command));

    if(!process->waitForFinished(3000)){
        ui->testLb->setText("Connection failed");
        qDebug() << "Forcefully killing process";
        process->kill();
        return;
    }

    if(process->exitCode() != 0){
        ui->testLb->setText("Connection failed");
        qDebug() << "Exit code: " << QString::number(process->exitCode());
        return;
    }

    ui->testLb->setText("Connection successful");
}
Example #5
0
//Run a shell command (return a list of lines)
QStringList Utils::runShellCommand( QString command )
{
 //split the command string with individual commands seperated by a ";" (if any)
 QStringList cmdl = command.split(";");
 QString outstr;
 //run each individual command
 for(int i=0;i<cmdl.length();i++){ 
   QProcess p;  
   //Make sure we use the system environment to properly read system variables, etc.
   p.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
   //Merge the output channels to retrieve all output possible
   p.setProcessChannelMode(QProcess::MergedChannels);   
   p.start(cmdl[i]);
   while(p.state()==QProcess::Starting || p.state() == QProcess::Running){
     p.waitForFinished(200);
     QCoreApplication::processEvents();
   }
   QString tmp = p.readAllStandardOutput();
   outstr.append(tmp);
 }
 if(outstr.endsWith("\n")){outstr.chop(1);} //remove the newline at the end 
 QStringList out = outstr.split("\n");
 //qDebug() << command;
 //for(int j=0; j<out.length();j++){ qDebug() << out[j];}
 return out;
}
void EngineSync::startSlaveProcess(int no)
{
	QDir programDir = QFileInfo( QCoreApplication::applicationFilePath() ).absoluteDir();
	QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
	QString engineExe = QFileInfo( QCoreApplication::applicationFilePath() ).absoluteDir().absoluteFilePath("JASPEngine");

	QStringList args;
	args << QString::number(no);

#ifdef __WIN32__
    env.insert("PATH", programDir.absoluteFilePath("R-3.0.0\\library\\RInside\\libs\\i386") + ";" + programDir.absoluteFilePath("R-3.0.0\\library\\Rcpp\\libs\\i386") + ";" + programDir.absoluteFilePath("R-3.0.0\\bin\\i386"));

    unsigned long processId = Process::currentPID();
    args << QString::number(processId);
#elif __APPLE__
    env.insert("DYLD_LIBRARY_PATH", programDir.absoluteFilePath("R-3.0.0/lib"));
#else
    env.insert("LD_LIBRARY_PATH", programDir.absoluteFilePath("R-3.0.0/lib") + ";" + programDir.absoluteFilePath("R-3.0.0/library/RInside/lib") + ";" + programDir.absoluteFilePath("R-3.0.0/library/Rcpp/lib"));
#endif

	env.insert("R_HOME", programDir.absoluteFilePath("R-3.0.0"));

	QProcess *slave = new QProcess(this);
	slave->setProcessEnvironment(env);
	slave->start(engineExe, args);

	_slaveProcesses.push_back(slave);

	connect(slave, SIGNAL(readyReadStandardOutput()), this, SLOT(subProcessStandardOutput()));
	connect(slave, SIGNAL(readyReadStandardError()), this, SLOT(subProcessStandardError()));
	connect(slave, SIGNAL(error(QProcess::ProcessError)), this, SLOT(subProcessError(QProcess::ProcessError)));
	connect(slave, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(subprocessFinished(int,QProcess::ExitStatus)));
	connect(slave, SIGNAL(started()), this, SLOT(subProcessStarted()));

}
Example #7
0
/*
 * Returns a string containing all AUR packages given a searchString parameter
 */
QByteArray UnixCommand::getAURPackageList(const QString &searchString)
{
  QByteArray result("");
  QProcess aur;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");

  aur.setProcessEnvironment(env);

  if (UnixCommand::getLinuxDistro() == ectn_KAOS)
    aur.start(StrConstants::getForeignRepositoryToolName() + " -l ");
  else
    aur.start(StrConstants::getForeignRepositoryToolName() + " -Ss " + searchString);

  aur.waitForFinished(-1);
  result = aur.readAll();

  if (UnixCommand::getLinuxDistro() == ectn_KAOS)
  {
    QString res = result;
    res.remove("\033");
    res.remove("[1m");
    res.remove("[m");
    res.remove("[1;32m");
    res.remove("[1;34m");
    res.remove("[1;36m");

    return res.toLatin1();
  }

  return result;
}
Example #8
0
void QNetCtlTool::chain()
{
    QProcess *proc = static_cast<QProcess*>(sender());
    const QString tag = proc->property("QNetCtlTag").toString();
    const QString info = proc->property("QNetCtlInfo").toString();
    if (proc->exitStatus() != QProcess::NormalExit || proc->exitCode()) {
        myClient->call(QDBus::NoBlock, "reply", tag, QString("ERROR: %1, %2").arg(proc->exitStatus()).arg(proc->exitCode()));
        return;
    }
    myClient->call(QDBus::NoBlock, "reply", tag, QString::fromLocal8Bit(proc->readAllStandardOutput()));

    QString cmd;
    if (tag == "remove_profile") {
        QFile::remove(gs_profilePath + info);
    } else if (tag == "scan_wifi") {
        myScanningDevices.removeAll(info);
        myUplinkingDevices.removeAll(info);
        cmd = TOOL(ip) + " link set " + info + " down";
    }

    if (cmd.isNull()) // should not happen
        return;

    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.remove("LC_ALL");
    env.remove("LANG");
    proc = new QProcess(this);
    proc->setProcessEnvironment(env);
//     proc->setProperty("QNetCtlTag", tag);
//     connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(reply()));
    connect (proc, SIGNAL(finished(int, QProcess::ExitStatus)), proc, SLOT(deleteLater()));
    proc->start(cmd, QIODevice::ReadOnly);
}
void ServerManager::startServer(int id) const
{
    QStringList args = QCoreApplication::arguments();
    args.removeFirst();

    if (id < 0) {
        id = startCounter;
    }

    TWebApplication::MultiProcessingModule mpm = Tf::app()->multiProcessingModule();
    if (mpm == TWebApplication::Hybrid || mpm == TWebApplication::Thread) {
        if (id < maxServers) {
            args.prepend(QString::number(id));
            args.prepend("-i");  // give ID for app server
        }
    }

    if (listeningSocket > 0) {
        args.prepend(QString::number(listeningSocket));
        args.prepend("-s");
    }

    QProcess *tfserver = new QProcess;
    serversStatus.insert(tfserver, id);

    connect(tfserver, SIGNAL(started()), this, SLOT(updateServerStatus()));
    connect(tfserver, SIGNAL(error(QProcess::ProcessError)), this, SLOT(errorDetect(QProcess::ProcessError)));
    connect(tfserver, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(serverFinish(int, QProcess::ExitStatus)));
    connect(tfserver, SIGNAL(readyReadStandardError()), this, SLOT(readStandardError()));    // For error notification

#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
    // Sets LD_LIBRARY_PATH environment variable
    QString ldpath = ".";  // means the lib dir
    QString sysldpath = QProcess::systemEnvironment().filter("LD_LIBRARY_PATH=", Qt::CaseSensitive).value(0).mid(16);
    if (!sysldpath.isEmpty()) {
        ldpath += ":";
        ldpath += sysldpath;
    }

    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.insert("LD_LIBRARY_PATH", ldpath);
    tSystemDebug("export %s=%s", "LD_LIBRARY_PATH", qPrintable(ldpath));

    QString preload = Tf::appSettings()->value(Tf::LDPreload).toString();
    if (!preload.isEmpty()) {
        env.insert("LD_PRELOAD", preload);
        tSystemDebug("export %s=%s", "LD_PRELOAD", qPrintable(preload));
    }
    tfserver->setProcessEnvironment(env);
#endif

    // Executes treefrog server
    tfserver->start(TFSERVER_CMD, args, QIODevice::ReadOnly);
    tfserver->closeReadChannel(QProcess::StandardOutput);
    tfserver->closeWriteChannel();
    tSystemDebug("tfserver started");
    ++startCounter;
}
void SearchPluginManager::update()
{
    QProcess nova;
    nova.setProcessEnvironment(QProcessEnvironment::systemEnvironment());

    const QStringList params {Utils::Fs::toNativePath(engineLocation() + "/nova2.py"), "--capabilities"};
    nova.start(Utils::ForeignApps::pythonInfo().executableName, params, QIODevice::ReadOnly);
    nova.waitForFinished();

    const QString capabilities = nova.readAll();
    QDomDocument xmlDoc;
    if (!xmlDoc.setContent(capabilities)) {
        qWarning() << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data();
        qWarning() << "Error: " << nova.readAllStandardError().constData();
        return;
    }

    const QDomElement root = xmlDoc.documentElement();
    if (root.tagName() != "capabilities") {
        qWarning() << "Invalid XML file for Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data();
        return;
    }

    for (QDomNode engineNode = root.firstChild(); !engineNode.isNull(); engineNode = engineNode.nextSibling()) {
        const QDomElement engineElem = engineNode.toElement();
        if (!engineElem.isNull()) {
            const QString pluginName = engineElem.tagName();

            std::unique_ptr<PluginInfo> plugin {new PluginInfo {}};
            plugin->name = pluginName;
            plugin->version = getPluginVersion(pluginPath(pluginName));
            plugin->fullName = engineElem.elementsByTagName("name").at(0).toElement().text();
            plugin->url = engineElem.elementsByTagName("url").at(0).toElement().text();

            const auto categories = engineElem.elementsByTagName("categories").at(0).toElement().text().split(' ');
            for (QString cat : categories) {
                cat = cat.trimmed();
                if (!cat.isEmpty())
                    plugin->supportedCategories << cat;
            }

            const QStringList disabledEngines = Preferences::instance()->getSearchEngDisabled();
            plugin->enabled = !disabledEngines.contains(pluginName);

            updateIconPath(plugin.get());

            if (!m_plugins.contains(pluginName)) {
                m_plugins[pluginName] = plugin.release();
                emit pluginInstalled(pluginName);
            }
            else if (m_plugins[pluginName]->version != plugin->version) {
                delete m_plugins.take(pluginName);
                m_plugins[pluginName] = plugin.release();
                emit pluginUpdated(pluginName);
            }
        }
    }
}
Example #11
0
/*
 * Initialize and launch process object
 */
bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args)
{
    static AssignProcessToJobObjectFun AssignProcessToJobObjectPtr = NULL;

    QMutexLocker lock(m_mutex_startProcess);
    emit messageLogged(commandline2string(program, args) + "\n");

    QProcessEnvironment env = process.processEnvironment();
    if(env.isEmpty()) env = QProcessEnvironment::systemEnvironment();
    env.insert("TEMP", QDir::toNativeSeparators(lamexp_temp_folder2()));
    env.insert("TMP", QDir::toNativeSeparators(lamexp_temp_folder2()));
    process.setProcessEnvironment(env);

    if(!AssignProcessToJobObjectPtr)
    {
        QLibrary Kernel32Lib("kernel32.dll");
        AssignProcessToJobObjectPtr = (AssignProcessToJobObjectFun) Kernel32Lib.resolve("AssignProcessToJobObject");
    }

    process.setProcessChannelMode(QProcess::MergedChannels);
    process.setReadChannel(QProcess::StandardOutput);
    process.start(program, args);

    if(process.waitForStarted())
    {

        if(AssignProcessToJobObjectPtr)
        {
            AssignProcessToJobObjectPtr(m_handle_jobObject, process.pid()->hProcess);
        }
        if(!SetPriorityClass(process.pid()->hProcess, BELOW_NORMAL_PRIORITY_CLASS))
        {
            SetPriorityClass(process.pid()->hProcess, IDLE_PRIORITY_CLASS);
        }

        lock.unlock();

        if(m_firstLaunch)
        {
            emit statusUpdated(0);
            m_firstLaunch = false;
        }

        return true;
    }

    emit messageLogged("Process creation has failed :-(");
    QString errorMsg= process.errorString().trimmed();
    if(!errorMsg.isEmpty()) emit messageLogged(errorMsg);

    process.kill();
    process.waitForFinished(-1);
    return false;
}
Example #12
0
bool versionControl::runMercurial(QString options) {

    if (!this->isMercurialThere)
        return false;

    QSettings settings;

    // get current model path from QSettings

    QString path = settings.value("files/currentFileName", "No model").toString();

    if (path == "No model")
        return false;

    // set up the environment for the spawned processes
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.insert("PATH", qgetenv("PATH"));
    // to be used as a username if one is not set
    env.insert("EMAIL", QHostInfo::localHostName());

    // make the QProcess
    QProcess * mercurial = new QProcess;
    mercurial->setWorkingDirectory(QDir::toNativeSeparators(path));
    mercurial->setProcessEnvironment(env);

    connect(mercurial, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
    connect(mercurial, SIGNAL(readyReadStandardOutput()), this, SLOT(standardOutput()));
    connect(mercurial, SIGNAL(readyReadStandardError()), this, SLOT(standardError()));

    // clear stdOut & stdErr texts
    stdOutText.clear();
    stdErrText.clear();

    // launch
    mercurial->start("hg " + options);

    // wait until complete, or 3 s
    bool noerror = mercurial->waitForFinished(3000);

    if (noerror) {
        // check output
        if (mercurial->exitCode() == 0) {
            delete mercurial;
            return true;
        } else {
            delete mercurial;
            return false;
        }

    }
    delete mercurial;
    return false;

}
Example #13
0
void LSession::startProcess(QString ID, QString command){
  QString logfile = QDir::homePath()+"/.lumina/logs/"+ID+".log";
  if(QFile::exists(logfile+".old")){ QFile::remove(logfile+".old"); }
  if(QFile::exists(logfile)){ QFile::rename(logfile,logfile+".old"); }
  QProcess *proc = new QProcess();
  proc->setProcessChannelMode(QProcess::MergedChannels);
  proc->setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
  proc->setStandardOutputFile(logfile);
  proc->start(command, QIODevice::ReadOnly);
  connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished()) );
  PROCS << proc;
}
Example #14
0
/*
 * Check if pkgfile is installed on the system
 */
bool UnixCommand::isPkgfileInstalled()
{
  QProcess pkgfile;

  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  pkgfile.setProcessEnvironment(env);

  pkgfile.start("pkgfile -V");
  pkgfile.waitForFinished();

  return pkgfile.exitStatus() == QProcess::NormalExit;
}
Example #15
0
bool OpenModelica::start(QString exeFile,QString &errMsg,int maxnsec)
{

    QFileInfo exeFileInfo(exeFile);
    QString exeDir = exeFileInfo.absolutePath();
    if(!QFile::exists(exeFile))
    {
        errMsg = "Cannot find model executable file : " + exeFile;
        return false;
    }

    QProcess simProcess;
    simProcess.setWorkingDirectory(exeDir);


#ifdef WIN32
    QString appPath = "\""+exeFile+"\"";
    // add OM path in PATH
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    QString omHome = env.value("OpenModelicaHome");
    omHome = omHome+QDir::separator()+"bin";
    QString mingw = env.value("OpenModelicaHome");
    mingw = mingw+QDir::separator()+"MinGW"+QDir::separator()+"bin";
    env.insert("PATH", env.value("Path") + ";"+omHome+";"+mingw);

    simProcess.setProcessEnvironment(env);

    //start process
    simProcess.start(appPath, QStringList());
#else
    QStringList arguments;
    arguments << "-c";
    arguments << "./"+exeFileInfo.fileName() << " > log.txt";
    simProcess.start("sh", arguments);
#endif

    int nmsec;
    if(maxnsec==-1)
        nmsec = -1;
    else
        nmsec = maxnsec*1000;
    bool ok = simProcess.waitForFinished(nmsec);
    if(!ok)
    {
        errMsg = "Simulation process failed or time limit reached";
        simProcess.close();
        return false;
    }

    QString output(simProcess.readAllStandardOutput());
    InfoSender::instance()->send(Info(output,ListInfo::OMCNORMAL2));
    return ok;
}
void AndroidSettingsWidget::manageAVD()
{
    QProcess *avdProcess = new QProcess();
    connect(this, SIGNAL(destroyed()), avdProcess, SLOT(deleteLater()));
    connect(avdProcess, SIGNAL(finished(int)), avdProcess, SLOT(deleteLater()));

    avdProcess->setProcessEnvironment(AndroidConfigurations::instance().androidToolEnvironment().toProcessEnvironment());
    QString executable = AndroidConfigurations::instance().androidToolPath().toString();
    QStringList arguments = QStringList() << QLatin1String("avd");

    avdProcess->start(executable, arguments);
}
Example #17
0
/*
 * Based on the given file, we use 'slocate' to suggest complete paths
 */
QStringList UnixCommand::getFilePathSuggestions(const QString &file)
{
  QProcess slocate;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  slocate.setProcessEnvironment(env);
  slocate.start("slocate -l 8 " + file);
  slocate.waitForFinished();

  QString ba = slocate.readAllStandardOutput();
  return ba.split("\n", QString::SkipEmptyParts);
}
Example #18
0
void QNetCtlTool::scanWifi(QString device)
{
    if (device.isNull() && sender())
        device = sender()->property("QNetCtlScanDevice").toString();

    if (myScanningDevices.contains(device))
        return;

    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.remove("LC_ALL");
    env.remove("LANG");
    QProcess *proc = new QProcess(this);
    proc->setProcessEnvironment(env);

    bool isDown = false;
    proc->start(TOOL(ip) + " link show " + device, QIODevice::ReadOnly);
    proc->waitForFinished();
    if (proc->exitStatus() == QProcess::NormalExit && !proc->exitCode())
        isDown = !QString::fromLocal8Bit(proc->readAllStandardOutput()).section('>', 0, 0).contains("UP");

    bool waitsForUp = myUplinkingDevices.contains(device);

    if (isDown) {
        if (!waitsForUp) {
            waitsForUp = true;
            myUplinkingDevices << device;
            proc->start(TOOL(ip) + " link set " + device + " up", QIODevice::ReadOnly);
            proc->waitForFinished();
        }

        // we're waiting for the device to come up
        delete proc;
        QTimer *t = new QTimer(this);
        t->setProperty("QNetCtlScanDevice", device);
        t->setSingleShot(true);
        connect(t, SIGNAL(timeout()), this, SLOT(scanWifi()));
        connect(t, SIGNAL(timeout()), t, SLOT(deleteLater()));
        t->start(500);
        return;
    }

    myScanningDevices << device;

    proc->setProperty("QNetCtlTag", "scan_wifi");
    proc->setProperty("QNetCtlInfo", device);
    // if we set it up, we've to set it back down through the chain slot
    connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), waitsForUp ? SLOT(chain()) : SLOT(reply()));
    connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), proc, SLOT(deleteLater()));
    proc->start(TOOL(iw) + " dev " + device + " scan");
}
Example #19
0
/*
 * Given a package name, which can be installed or uninstalled on system
 * returns a string containing all the files inside it, the file list is
 * obtained using pkgfile
 */
QByteArray UnixCommand::getPackageContentsUsingPkgfile(const QString &pkgName)
{
  QByteArray result("");
  QProcess pkgfile;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  pkgfile.setProcessEnvironment(env);

  pkgfile.start("pkgfile -l " + pkgName);
  pkgfile.waitForFinished();
  result = pkgfile.readAllStandardOutput();

  return result;
}
Example #20
0
void LSession::startProcess(QString ID, QString command){
  QString dir = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/logs";
  if(!QFile::exists(dir)){ QDir tmp(dir); tmp.mkpath(dir); }
  QString logfile = dir+"/"+ID+".log";
  if(QFile::exists(logfile+".old")){ QFile::remove(logfile+".old"); }
  if(QFile::exists(logfile)){ QFile::rename(logfile,logfile+".old"); }

  QProcess *proc = new QProcess();
  proc->setProcessChannelMode(QProcess::MergedChannels);
  proc->setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
  proc->setStandardOutputFile(logfile);
  proc->start(command, QIODevice::ReadOnly);
  connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished()) );
  PROCS << proc;
}
Example #21
0
QStringList MainWindow::runShellCommand(QString cmd){
   QProcess p;  
   //Make sure we use the system environment to properly read system variables, etc.
   p.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
   //Merge the output channels to retrieve all output possible
   p.setProcessChannelMode(QProcess::MergedChannels);   
   p.start(cmd);
   while(p.state()==QProcess::Starting || p.state() == QProcess::Running){
     p.waitForFinished(200);
     QCoreApplication::processEvents();
   }
   QString tmp = p.readAllStandardOutput();
    if(tmp.endsWith("\n")){ tmp.chop(1); }
    return tmp.split("\n");
}
Example #22
0
QStringList AuthorizationManager::getUserGroups(QString user){
  QProcess proc;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_All", "C");
  proc.setProcessEnvironment(env);
  proc.setProcessChannelMode(QProcess::MergedChannels);
  proc.start("id", QStringList() << "-nG" << user);
  if(!proc.waitForStarted(30000)){ return QStringList(); } //process never started - max wait of 30 seconds
  while(!proc.waitForFinished(500)){
    if(proc.state() != QProcess::Running){ break; } //somehow missed the finished signal
    QCoreApplication::processEvents();
  }
  QStringList out = QString(proc.readAllStandardOutput()).split(" ");
  return out;	
}
Example #23
0
/*
 * Pings google site, to make sure internet is OK
 */
bool UnixCommand::doInternetPingTest()
{
  QProcess ping;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  ping.setProcessEnvironment(env);
  ping.start("ping -c 1 -W 3 www.google.com");

  ping.waitForFinished();

  int res = ping.exitCode();
  ping.close();

  return (res == 0);
}
Example #24
0
/*
 * Performs a pacman query
 */
QByteArray UnixCommand::performQuery(const QStringList args)
{
  QByteArray result("");
  QProcess pacman;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  env.insert("LC_ALL", "C");
  pacman.setProcessEnvironment(env);

  pacman.start("pkg", args);
  pacman.waitForFinished();
  result = pacman.readAllStandardOutput();
  pacman.close();

  return result;
}
Example #25
0
/*
 * Performs a yourt command
 */
QByteArray UnixCommand::performAURCommand(const QString &args)
{
  QByteArray result("");
  QProcess aur;

  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  aur.setProcessEnvironment(env);

  aur.start(StrConstants::getForeignRepositoryToolName() + " " + args);
  aur.waitForFinished(-1);
  result = aur.readAllStandardOutput();

  aur.close();
  return result;
}
Example #26
0
int QvkPulse::getPulseInputDevicesCount()
{
  QProcess Process;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "c");
  Process.setProcessEnvironment(env);
  Process.start( "pactl list" );
  Process.waitForFinished();
  QString output = Process.readAllStandardOutput();
  Process.close();
  //delete Process;
  
  QStringList list = output.split( "\n" );

  QStringList result = list.filter( "Source #", Qt::CaseInsensitive );
  return result.count();
}
Example #27
0
/*
 * Retrieves the system arch
 */
QString UnixCommand::getSystemArchitecture()
{
  QStringList slParam;
  QProcess proc;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  proc.setProcessEnvironment(env);

  slParam << "-m";
  proc.start("uname", slParam);
  proc.waitForFinished();

  QString out = proc.readAllStandardOutput();
  proc.close();

  return out;
}
/**
 * @brief KernelModel::getRunningKernel get running kernel in the system
 * @return string with the version of running kernel
 */
QString
KernelModel::getRunningKernel() const
{
    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    env.insert( "LANG", "C" );
    env.insert( "LC_MESSAGES", "C" );
    env.insert( "LC_ALL", "C" );

    QProcess uname;
    uname.setProcessEnvironment( env );

    uname.start( "uname", QStringList() << "-r" );
    uname.waitForFinished();
    QString result = uname.readAllStandardOutput();
    uname.close();
    QStringList aux = result.split( ".", QString::SkipEmptyParts );
    return QString( "linux%1%2" ).arg( aux.at( 0 ) ).arg( aux.at( 1 ) );
}
void SyncProcess::startQProcess(QProcess& process)
{
    const QString command = generateFullCommand();
    if (command.isEmpty())
        throw SyncProcessException("Cannot start process '" + generateDescription() + "'. The full command is '" + command + "'.");

    if (!mStdInFile.isEmpty())
        process.setStandardInputFile(mStdInFile);

    process.setProcessEnvironment(generateFullEnvironment());
    mDiagnosticInfo += QObject::tr("Starting process '%1'\n").arg(generateDescription());
    process.setWorkingDirectory(mWorkingDirectory);
    process.start(command, generateFullArguments());
    process.waitForStarted();

    if (process.state() != QProcess::Running)
        throw SyncProcessException("Starting process '" + generateDescription() + "' failed. The process is not in a running state.");
}
Example #30
0
/*
 * Executes given command and returns the StandardError Output.
 */
QString UnixCommand::runCommand(const QString& commandToRun)
{
  QProcess proc;
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.remove("LANG");
  env.remove("LC_MESSAGES");
  env.insert("LANG", "C");
  env.insert("LC_MESSAGES", "C");
  proc.setProcessEnvironment(env);
  proc.start(commandToRun);
  proc.waitForStarted();
  proc.waitForFinished(-1);

  QString res = proc.readAllStandardError();
  proc.close();

  return res;
}