KProcess::KProcess(KProcessPrivate *d, QObject *parent) : QProcess(parent), d_ptr(d) { d_ptr->q_ptr = this; setOutputChannelMode(ForwardedChannels); }
void GPGProc::resetProcess(const QString &binary) { GnupgBinary *bin = lastBinary(); QString executable; //qDebug() << "bin:" << binary; if (binary.isEmpty()) { //executable = KGpgSettings::gpgBinaryPath(); QString appPath = qApp->applicationDirPath(); QString gpgBin; #ifdef Q_WS_WIN gpgBin = appPath + "/bin/gpg.exe"; #endif #ifdef Q_WS_MAC gpgBin = appPath + "/../../../bin/gpg-mac"; #endif #ifdef Q_WS_X11 gpgBin = appPath + "/bin/gpg"; #endif executable = gpgBin; } else executable = binary; if (bin->binary() != executable) bin->setBinary(executable); //qDebug() << "ex: " << executable; setProgram(executable, bin->standardArguments()); setOutputChannelMode(OnlyStdoutChannel); disconnect(SIGNAL(finished(int,QProcess::ExitStatus))); disconnect(SIGNAL(lineReadyStandardOutput())); }
ClipCommandProcess::ClipCommandProcess(const ClipAction& action, const ClipCommand& command, const QString& clip, History* history, const HistoryItem* original_item) : KProcess(), m_history(history), m_historyItem(original_item), m_newhistoryItem() { QHash<QChar,QString> map; map.insert( 's', clip ); // support %u, %U (indicates url param(s)) and %f, %F (file param(s)) map.insert( 'u', clip ); map.insert( 'U', clip ); map.insert( 'f', clip ); map.insert( 'F', clip ); const QStringList matches = action.regExpMatches(); // support only %0 and the first 9 matches... const int numMatches = qMin(10, matches.count()); for ( int i = 0; i < numMatches; ++i ) { map.insert( QChar( '0' + i ), matches.at( i ) ); } setOutputChannelMode(OnlyStdoutChannel); setShellCommand(KMacroExpander::expandMacrosShellQuote( command.command, map ).trimmed()); connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(slotFinished(int,QProcess::ExitStatus))); if (command.output != ClipCommand::IGNORE) { connect(this, SIGNAL(readyRead()), SLOT(slotStdOutputAvailable())); } if (command.output != ClipCommand::REPLACE) { m_historyItem = 0L; // Don't replace } }
/** * 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(); }
/** * Executes a grep process using the given command line arguments. * The full path to the grep executable should be set in the "Path" key * under the "grep" group. * @param slArgs Command line arguments for grep * @return true if successful, false otherwise */ bool GrepFrontend::run(const QStringList& slArgs) { // qDebug() << "GrepFrontend.run() \n"; QStringList slCmdLine; // Set the command line arguments slCmdLine += slArgs; setOutputChannelMode(KProcess::MergedChannels); #if 0 // Use verbose mode, if supported // if (s_nSupArgs & VerboseOut) //slCmdLine << "-v"; // Project-specific options if (s_nProjArgs & Kernel) slCmdLine << "-k"; if (s_nProjArgs & InvIndex) slCmdLine << "-q"; if (s_nProjArgs & NoCompression) slCmdLine << "-c"; if (s_nProjArgs & s_nSupArgs & SlowPathDef) slCmdLine << "-D"; #endif // slCmdLine << "/var/log/Xorg.0.log"; // slCmdLine << "hi"; qDebug() << "testing! " << slCmdLine << s_sProjPath; // Run a new process if (!Frontend::run("ls", slCmdLine, s_sProjPath)) { emit aborted(); return false; } waitForFinished(); qDebug() << "done"; return true; }
bool buildFrontEnd::build(QString s_sProjPath) { qDebug ()<< "buildFrontEnd::build(): "<< s_sProjPath; QStringList slCmdLine; // QString s_sProjPath = "."; // FIXME: put in project path setOutputChannelMode(KProcess::MergedChannels); // connect(this, SIGNAL(readyRead()), // this, SLOT(slotDisplayResults())); // Run a new process if (!Frontend::run("make", slCmdLine, s_sProjPath)) { emit aborted(); return false; } return true; }
/** * Class constructor. * @param nRecordSize The number of fields in each record * @param bAutoDelete (Optional) true to delete the object when the process * terminates, false (default) otherwise */ Frontend::Frontend(uint nRecordSize, bool bAutoDelete) : KProcess(), m_nRecords(0), m_pHeadToken(NULL), m_pTailToken(NULL), m_pCurToken(NULL), m_bAutoDelete(bAutoDelete), m_bInToken(false), m_nRecordSize(nRecordSize) { setOutputChannelMode(SeparateChannels); // Parse data on the standard output connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadStdout2())); // Parse data on the standard error connect(this, SIGNAL(readyReadStandardError()), this, SLOT(slotReadStderr2())); // Delete the process object when the process exits connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotFinished(int, QProcess::ExitStatus))); }