Calamares::JobResult CreatePartitionTableJob::exec() { Report report( 0 ); QString message = tr( "The installer failed to create a partition table on %1." ).arg( m_device->name() ); CoreBackend* backend = CoreBackendManager::self()->backend(); QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) ); if ( !backendDevice.data() ) { return Calamares::JobResult::error( message, tr( "Could not open device %1." ).arg( m_device->deviceNode() ) ); } QScopedPointer< PartitionTable > table( createTable() ); cDebug() << "Creating new partition table of type" << table->typeName() << ", uncommitted yet:\n" << table; QProcess lsblk; lsblk.setProgram( "lsblk" ); lsblk.setProcessChannelMode( QProcess::MergedChannels ); lsblk.start(); lsblk.waitForFinished(); cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput(); QProcess mount; mount.setProgram( "mount" ); mount.setProcessChannelMode( QProcess::MergedChannels ); mount.start(); mount.waitForFinished(); cDebug() << "mount:\n" << mount.readAllStandardOutput(); bool ok = backendDevice->createPartitionTable( report, *table ); if ( !ok ) { return Calamares::JobResult::error( message, QString( "Text: %1\nCommand: %2\nOutput: %3\nStatus: %4" ) .arg( report.toText() ) .arg( report.command() ) .arg( report.output() ) .arg( report.status() ) ); } return Calamares::JobResult::ok(); }
QStringList MainWindow::exec(const QString &pExe, const QString &pDir) { QProcess lProcess; lProcess.setProcessChannelMode(QProcess::MergedChannels); if(!pDir.isEmpty()) { lProcess.setWorkingDirectory(pDir); } lProcess.start(pExe); if(!lProcess.waitForFinished()) { return QStringList() << lProcess.errorString(); } //! TODO: find a better way to do this! QList<QByteArray> lTempLines = lProcess.readAll().split('\n'); QStringList lStringList; for(int i=0;i<lTempLines.size();i++) { QString lLine(lTempLines[i]); if(lLine.isEmpty()) continue; lStringList.append(lLine); } return lStringList; }
void MainWindow::testPass() { QString program = "sudo"; QStringList arguments; arguments << "-S"; arguments << "-k"; arguments << "true"; QProcess *tP = new QProcess(this); tP->setProcessChannelMode(QProcess::MergedChannels); tP->start(program, arguments); tP->write(passwordLineEdit->text().toLatin1() + "\n"); tP->write(passwordLineEdit->text().toLatin1() + "\n"); tP->write(passwordLineEdit->text().toLatin1() + "\n"); while(tP->state() == QProcess::Starting || tP->state() == QProcess::Running ) { tP->waitForFinished(500); QCoreApplication::processEvents(); } if ( tP->exitCode() != 0 ) { QString tmp; tmp.setNum(tries-1); labelBadPW->setText(tr("Invalid Password! Tries Left: %1").arg(tmp) ); tries--; if ( tries == 0 ) exit(1); passwordLineEdit->setText(""); } else { startSudo(); } }
bool LPBackend::datasetInfo(QString dataset, int& time, int& numToKeep){ QString cmd = "lpreserver listcron"; //Need output, so run this in a QProcess QProcess *proc = new QProcess; proc->setProcessChannelMode(QProcess::MergedChannels); proc->start(cmd); proc->waitForFinished(); QStringList out = QString(proc->readAllStandardOutput()).split("\n"); delete proc; //Now process the output bool ok = false; for(int i=0; i<out.length(); i++){ if(out[i].section(" - ",0,0).simplified() == dataset){ //Get time schedule (in integer format) QString sch = out[i].section(" - ",1,1).simplified(); if(sch.startsWith("daily@")){ time = sch.section("@",1,1).simplified().toInt(); } else if(sch=="5min"){time = -5;} else if(sch=="10min"){time = -10;} else if(sch=="30min"){time = -30;} else{ time = -60; } //hourly //Get total snapshots numToKeep = out[i].section("- total:",1,1).simplified().toInt(); ok=true; break; } } //qDebug() << "lpreserver cronsnap:\n" << out << QString::number(time) << QString::number(numToKeep); return ok; }
bool LPBackend::replicationInfo(QString dataset, QString& remotehost, QString& user, int& port, QString& remotedataset, int& time){ QString cmd = "lpreserver replicate list"; //Need output, so run this in a QProcess QProcess *proc = new QProcess; proc->setProcessChannelMode(QProcess::MergedChannels); proc->start(cmd); proc->waitForFinished(); QStringList out = QString(proc->readAllStandardOutput()).split("\n"); delete proc; //Now process the output bool ok = false; for(int i=0; i<out.length(); i++){ if(out[i].contains("->") && out[i].startsWith(dataset)){ QString data = out[i].section("->",1,1); user = data.section("@",0,0); remotehost = data.section("@",1,1).section("[",0,0); port = data.section("[",1,1).section("]",0,0).toInt(); remotedataset = data.section(":",1,1).section(" Time",0,0); QString synchro = data.section("Time:",1,1).simplified(); if(synchro == "sync"){ time = -1; } else{ time = synchro.toInt(); } ok = true; break; } } return ok; }
DeviceList DeviceInfo::retrieveDevices(DeviceType type) { qDebug("DeviceInfo::retrieveDevices: %d", type); DeviceList l; QRegExp rx_device("^(\\d+): (.*)"); if (QFile::exists("dxlist.exe")) { QProcess p; p.setProcessChannelMode( QProcess::MergedChannels ); QStringList arg; if (type == Sound) arg << "-s"; else arg << "-d"; p.start("dxlist", arg); if (p.waitForFinished()) { QByteArray line; while (p.canReadLine()) { line = p.readLine().trimmed(); qDebug("DeviceInfo::retrieveDevices: '%s'", line.constData()); if ( rx_device.indexIn(line) > -1 ) { int id = rx_device.cap(1).toInt(); QString desc = rx_device.cap(2); qDebug("DeviceInfo::retrieveDevices: found device: '%d' '%s'", id, desc.toUtf8().constData()); l.append( DeviceData(id, desc) ); } } } } return l; }
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; }
void ProcessLauncherHelper::launch(WebKit::ProcessLauncher* launcher) { QString applicationPath = "%1 %2"; if (QFile::exists(QCoreApplication::applicationDirPath() + "/QtWebProcess")) { applicationPath = applicationPath.arg(QCoreApplication::applicationDirPath() + "/QtWebProcess"); } else { applicationPath = applicationPath.arg("QtWebProcess"); } QString program(applicationPath.arg(m_server.serverName())); QProcess* webProcess = new QProcess(); webProcess->setProcessChannelMode(QProcess::ForwardedChannels); webProcess->start(program); if (!webProcess->waitForStarted()) { qDebug() << "Failed to start" << program; ASSERT_NOT_REACHED(); delete webProcess; return; } setpriority(PRIO_PROCESS, webProcess->pid(), 10); m_items.append(WorkItem::create(launcher, &WebKit::ProcessLauncher::didFinishLaunchingProcess, webProcess, m_server.serverName()).leakPtr()); }
void TCPBase::RealStart() { connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); IPCSocket = 0; #ifdef HWLIBRARY QThread *thread = new QThread; EngineInstance *instance = new EngineInstance; instance->port = IPCServer->serverPort(); instance->moveToThread(thread); connect(thread, SIGNAL(started()), instance, SLOT(start(void))); connect(instance, SIGNAL(finished()), thread, SLOT(quit())); connect(instance, SIGNAL(finished()), instance, SLOT(deleteLater())); connect(instance, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); #else QProcess * process; process = new QProcess(); connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); QStringList arguments=getArguments(); #ifdef QT_DEBUG // redirect everything written on stdout/stderr process->setProcessChannelMode(QProcess::ForwardedChannels); #endif process->start(bindir->absolutePath() + "/hwengine", arguments); #endif m_hasStarted = true; }
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; }
void powotsimulator::symbol_list_file(QString *filepath, QStringList *symbol_list){ QStringList symbol_dump; QString cmd; cmd = symbollist_cmd + *filepath; qDebug()<<"(powotsimulator) symbollist cmd:"<<cmd; QProcess terminal; terminal.setProcessChannelMode(QProcess::MergedChannels); terminal.start(cmd); terminal.waitForFinished(-1); QByteArray temp = terminal.readAllStandardOutput(); convert_bytearray_stringlist(&temp, &symbol_dump); if(symbol_dump.isEmpty()){ err_message.display_error(SYMBOLLIST_FAILED); qDebug()<<"(powotsimulator) Aborting ..."; exit(-1); } for(int i = 0; i < symbol_dump.size(); i++){ *symbol_list << symbol_dump.at(i).section(' ', 2, 2); } /*qDebug()<<"SYMBOLS:"; for(int i = 0; i < symbol_list->size(); i++) { qDebug()<<"symbollist_file: ***"<<symbol_list->at(i)<<" size: "<<symbol_list->at(i).size(); }*/ }
bool DriveFormatThread::partitionDrive() { QByteArray partitionTable; if (_reformatBoot) partitionTable = "2048,129024,0E\n"; /* 63 MB FAT partition LBA */ // partitionTable = "0,128,6\n"; /* 64 MB FAT partition */ partitionTable += "131072,,L\n"; /* Linux partition with all remaining space */ partitionTable += "0,0\n"; partitionTable += "0,0\n"; if (!_reformatBoot) partitionTable += "0,0\n"; //QString cmd = QString("/sbin/sfdisk -H 32 -S 32 /dev/")+_dev; QString cmd = QString("/sbin/sfdisk -H 255 -S 63 -u S /dev/")+_dev; QProcess proc; proc.setProcessChannelMode(proc.MergedChannels); proc.start(cmd); proc.write(partitionTable); proc.closeWriteChannel(); proc.waitForFinished(-1); //qDebug() << "partitioning" << cmd; //qDebug() << partitionTable; return proc.exitCode() == 0; }
HacServer::HacServer(QObject *parent) : QObject(parent) { qDebug() << "HacServer::HacServer"; // init qws server server = QWSServer::instance(); QScreen *screen = QScreen::instance(); server->setMaxWindowRect(QRect(WINDOW_X, WINDOW_Y, WINDOW_W, WINDOW_H)); // init status bar statusBar = new StatusBar; connect(statusBar, SIGNAL(homeClicked()), this, SLOT(OnHomeClicked())); connect(statusBar, SIGNAL(backClicked()), this, SLOT(OnBackClicked())); connect(statusBar, SIGNAL(clockClicked()), this, SLOT(OnClockClicked())); statusBar->setGeometry(STATUSBAR_X, STATUSBAR_Y, STATUSBAR_W, STATUSBAR_H); statusBar->show(); // init auto start applications QProcess *myApp = new QProcess; myApp->setProcessChannelMode(QProcess::ForwardedChannels); myApp->start(APP_HAC01_BIN); myApp->waitForStarted(); }
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; }
QString ProbeABIDetector::qtCoreFromLsof(qint64 pid) const { QString lsofExe; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) lsofExe = QStandardPaths::findExecutable(QStringLiteral("lsof")); // on OSX it's in sbin, which usually but not always is in PATH... if (lsofExe.isEmpty()) lsofExe = QStandardPaths::findExecutable(QStringLiteral("lsof"), QStringList() << QStringLiteral( "/usr/sbin") << QStringLiteral("/sbin")); #endif if (lsofExe.isEmpty()) lsofExe = QStringLiteral("lsof"); // maybe QProcess has more luck QProcess proc; proc.setProcessChannelMode(QProcess::SeparateChannels); proc.setReadChannel(QProcess::StandardOutput); proc.start(lsofExe, QStringList() << QStringLiteral("-Fn") << QStringLiteral( "-n") << QStringLiteral("-p") << QString::number(pid)); proc.waitForFinished(); forever { const QByteArray line = proc.readLine(); if (line.isEmpty()) break; if (containsQtCore(line)) return QString::fromLocal8Bit(line.mid(1).trimmed()); // strip the field identifier } return QString(); }
//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; }
bool CameraOutV4L2::sudo(const QString &command, const QStringList &argumments, const QString &password) const { if (password.isEmpty()) return false; QProcess echo; QProcess su; echo.setStandardOutputProcess(&su); switch (this->m_rootMethod) { case RootMethodSu: { QStringList args; for (QString arg: argumments) args << arg.replace(" ", "\\ "); echo.start("echo", {password}); su.start("su", {"-c", command + " " + args.join(" ")}); break; } case RootMethodSudo: { echo.start("echo", {password}); su.start("sudo", QStringList{"-S", command} << argumments); break; } } su.setProcessChannelMode(QProcess::ForwardedChannels); echo.waitForStarted(); if (!su.waitForFinished(this->m_passwordTimeout)) { su.kill(); echo.waitForFinished(); return false; } echo.waitForFinished(); if (su.exitCode()) { QByteArray outMsg = su.readAllStandardOutput(); if (!outMsg.isEmpty()) qDebug() << outMsg.toStdString().c_str(); QByteArray errorMsg = su.readAllStandardError(); if (!errorMsg.isEmpty()) qDebug() << errorMsg.toStdString().c_str(); return false; } return true; }
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; }
bool KPBinaryIface::checkDir(const QString& possibleDir) { bool ret = false; QString possiblePath = path(possibleDir); kDebug() << "Testing " << possiblePath << "..."; QProcess process; process.setProcessChannelMode(QProcess::MergedChannels); process.start(possiblePath, m_binaryArguments); bool val = process.waitForFinished(); if (val && (process.error() != QProcess::FailedToStart)) { m_isFound = true; QString stdOut(process.readAllStandardOutput()); if (parseHeader(stdOut)) { m_pathDir = possibleDir; writeConfig(); kDebug() << "Found " << path() << " version: " << version(); ret = true; } else { // TODO: do something if the version is not right or not found } } emit signalBinaryValid(); return ret; }
bool FileEnvProcess::startDetached(const QString& program) { QByteArray programBa = program.toLatin1(); const char* programCharPtr = programBa.data(); QString* tmpFileNameStrPtr = new QString("/tmp/tmpRideFile.bash"); QFile* tmpRideFilePtr = new QFile(*tmpFileNameStrPtr); tmpRideFilePtr->open(QIODevice::WriteOnly); addHeader(tmpRideFilePtr); tmpRideFilePtr->write(programCharPtr); tmpRideFilePtr->write("\nrm /tmp/tmpRideFile.bash"); tmpRideFilePtr->write("\necho \"Finished execution.\""); tmpRideFilePtr->close(); QStringList stringlst; stringlst.push_back("+x"); stringlst.push_back("/tmp/tmpRideFile.bash"); QProcess qprocess; qprocess.setProcessChannelMode(QProcess::MergedChannels); //QByteArray output = qprocess.readAll(); qprocess.execute("chmod", stringlst); int rtn = qprocess.startDetached(*tmpFileNameStrPtr); //don't run this->execute; this would result in infinate recursion!!! //cout << cct::bold("\nOutput: ") << output.data() << cct::bold("\nEnd of output") << endl; return rtn; }
int main() { #ifndef QT_NO_PROCESS QProcess process; process.setProcessChannelMode(QProcess::ForwardedChannels); if (process.processChannelMode() != QProcess::ForwardedChannels) return -1; process.start("testProcessEcho/testProcessEcho"); if (!process.waitForStarted(5000)) return -1; if (process.write("forwarded\n") != 10) return -1; process.waitForReadyRead(250); if (process.bytesAvailable() != 0) return -1; process.closeWriteChannel(); process.waitForFinished(5000); #endif return 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; }
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; }
void ProgramTab::sendProgram() { if (m_programmerPath.isEmpty()) return; if (isModified()) { QMessageBox::information(NULL, QObject::tr("Fritzing"), tr("The file '%1' must be saved before it can be sent to the programmer.").arg(m_filename)); return; } m_programButton->setEnabled(false); QString language = m_languageComboBox->currentText(); if (language.compare("picaxe", Qt::CaseInsensitive) == 0) { QProcess * process = new QProcess(this); process->setProcessChannelMode(QProcess::MergedChannels); process->setReadChannel(QProcess::StandardOutput); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(programProcessFinished(int, QProcess::ExitStatus))); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(programProcessReadyRead())); QStringList args; args.append(QString("-c%1").arg(m_portComboBox->currentText())); args.append(m_filename); m_console->setPlainText(""); process->start(m_programmerPath, args); }
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; }
DCDCompletion QcdAssist::sendRequestToDCD(QByteArray& filedata, uint pos) { QProcess proc; proc.setProcessChannelMode(QProcess::MergedChannels); proc.start(QcdAssist::dcdClient(), QStringList() //<< QString(QLatin1String("-p%1")).arg(QcdAssist::dcdPort) << QString(QLatin1String("-c%1")).arg(pos) ); proc.write(filedata); proc.closeWriteChannel(); if(!proc.waitForFinished(QcdAssist::waitForReadyReadTimeout)) { //Core::MessageManager::write(QLatin1String("qcdassist error: unable to complete: client didn't finish in time")); proc.close(); } else if(proc.exitCode() != 0) { //Core::MessageManager::write(QString(QLatin1String("qcdassist error: unable to complete: %1")).arg(proc.exitCode())); QByteArray arr = proc.readAll(); //Core::MessageManager::write(QString::fromUtf8(arr.data(),arr.length())); } else { // everything Ok return processCompletion(proc.readAllStandardOutput()); } return DCDCompletion(); }
void Oven::cook(QString inputContents, QString scriptContents) { QTemporaryFile file; QProcess process; if (file.open()) { QString filename = file.fileName(); file.write(scriptContents.toUtf8()); if (!file.error()) { file.close(); process.setProcessChannelMode(QProcess::ForwardedChannels); process.start("bash", QStringList() << filename); QTextStream inputStream(&process); inputStream << inputContents; inputStream.flush(); process.closeWriteChannel(); if (process.waitForStarted() && process.waitForFinished()) { // success! return; } } } if (file.error() != QTemporaryFile::NoError) { emit error(file.errorString()); } else { emit error(process.errorString()); } // error. return; }
/* QString Process::getPippedShellCommand(QString idCommand1, QString idParam1, QString idCommand2, QString idParam2){ QString command; command = this->shsc.getPippedCommand(idCommand1, idCommand2, idParam1, idParam2); if (command.isEmpty() == false){ this->setCom(true); } else { this->setCom(false); } return command; } */ QString Process::execShellProcess(QString idCommand, QString idParam = ""){ QString result, command; QProcess *pro = NULL; //Get command command = QString(idCommand+" "+idParam); //Process command pro = new QProcess(); pro->setProcessChannelMode(QProcess::MergedChannels); pro->start(command); if (pro->waitForFinished()) { result = QString(pro->readAll()); //Trim if (result != NULL && result.isEmpty() == false){ result = result.trimmed(); } } pro->close(); //Free mem if (pro != NULL){ delete pro; } return result; }
static QString recurse(KProcess::OutputChannelMode how) { QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); p.start(gargv[0], QStringList() << QString::number((int)how)); p.waitForFinished(); return p.readAllStandardOutput(); }
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; }