A QProcess subclass for code-blocking process execution. More...
#include <klfblockprocess.h>
Public Slots | |
bool | startProcess (QStringList cmd, QByteArray stdindata, QStringList env=QStringList()) |
bool | startProcess (QStringList cmd, QStringList env=QStringList()) |
QString | readStderrString () |
QString | readStdoutString () |
Public Member Functions | |
KLFBlockProcess (QObject *parent=0) | |
~KLFBlockProcess () | |
void | setProcessAppEvents (bool processAppEvents) |
QByteArray | getAllStderr () |
QByteArray | getAllStdout () |
bool | processNormalExit () const |
int | processExitStatus () const |
virtual QString | getInterpreterPath (const QString &ext) |
The interpter path to use for the given extension. | |
Static Public Member Functions | |
static QString | detectInterpreterPath (const QString &interp, const QStringList &addpaths=QStringList()) |
A QProcess subclass for code-blocking process execution.
A Code-blocking (but not GUI-blocking) process executor
Use for example like:
KLFBlockProcess proc; QStringList args; args << "ls" << "/dev"; proc.startProcess(args); QString alldevices = proc.readStdoutString();
This class provides functionality for passing data to STDIN and getting data from STDOUT and STDERR afterwards.
Definition at line 56 of file klfblockprocess.h.
KLFBlockProcess::KLFBlockProcess | ( | QObject * | parent = 0 | ) |
Normal constructor, like QProcess constructor
Definition at line 97 of file klfblockprocess.cpp.
References QObject::connect(), and QProcess::finished().
Normal destructor
Definition at line 105 of file klfblockprocess.cpp.
QByteArray KLFBlockProcess::getAllStderr | ( | ) | [inline] |
Returns all standard error output as a QByteArray. This function is to standardize the readStderr() and readAllStandardError() functions in QT 3 or QT 4 respectively
Definition at line 72 of file klfblockprocess.h.
References QProcess::readAllStandardError().
QByteArray KLFBlockProcess::getAllStdout | ( | ) | [inline] |
Returns all standard output as a QByteArray. This function is to standardize the readStdout() and readAllStandardOutput() functions in QT 3 or QT 4 respectively
Definition at line 78 of file klfblockprocess.h.
References QProcess::readAllStandardOutput().
QString KLFBlockProcess::getInterpreterPath | ( | const QString & | ext | ) | [virtual] |
The interpter path to use for the given extension.
This function will be queried by startProcess() when we have to execute a script.
Subclasses may reimplement to e.g. query user settings etc. Subclasses may of course also make use of detectInterpreterPath().
The default implementation treats some common script extensions ("py", "rb", "sh") and tries to find the interpreter using detectInterpreterPath().
Definition at line 118 of file klfblockprocess.cpp.
References KLF_DEBUG_BLOCK, KLF_FUNC_NAME, and klfDbg.
Referenced by startProcess().
int KLFBlockProcess::processExitStatus | ( | ) | const [inline] |
Same as QProcess::exitCode()
Definition at line 88 of file klfblockprocess.h.
References QProcess::exitCode().
bool KLFBlockProcess::processNormalExit | ( | ) | const [inline] |
Same as QProcess::exitStatus()==NormalExit
Definition at line 83 of file klfblockprocess.h.
References QProcess::exitStatus().
QString KLFBlockProcess::readStderrString | ( | ) | [inline, slot] |
Same as getAllStderr(), except result is returned here as QString.
Definition at line 128 of file klfblockprocess.h.
References QString::fromLocal8Bit().
QString KLFBlockProcess::readStdoutString | ( | ) | [inline, slot] |
Same as getAllStdout(), except result is returned here as QString.
Definition at line 132 of file klfblockprocess.h.
References QString::fromLocal8Bit().
void KLFBlockProcess::setProcessAppEvents | ( | bool | processAppEvents | ) | [inline] |
specify whether or not to call regularly qApp->processEvents() while executing. This will prevent the GUI to freeze. Enabled is the default. However you can choose to disable this behavior by passing FALSE here.
Definition at line 68 of file klfblockprocess.h.
bool KLFBlockProcess::startProcess | ( | QStringList | cmd, |
QByteArray | stdindata, | ||
QStringList | env = QStringList() |
||
) | [slot] |
Starts cmd (which is a list of arguments, the first being the program itself) and blocks until process stopped. The QT event loop is updated regularly so that the GUI doesn't freeze.
Read result with QProcess::readStdout() and QProcess::readStderr(), get process exit info with processNormalExit() and processExitStatus().
Definition at line 137 of file klfblockprocess.cpp.
References QList::begin(), QProcess::closeWriteChannel(), QByteArray::constData(), QThread::currentThread(), QProcess::environment(), QList::erase(), QProcess::error(), getInterpreterPath(), KLF_ASSERT_CONDITION, KLF_DEBUG_BLOCK, KLF_FUNC_NAME, klfDbg, QList::last(), QList::prepend(), QCoreApplication::processEvents(), QProcess::program(), QProcess::setEnvironment(), QByteArray::size(), QList::size(), QProcess::start(), QString::toLocal8Bit(), QProcess::waitForFinished(), QProcess::waitForStarted(), and QIODevice::write().
Referenced by startProcess().
bool KLFBlockProcess::startProcess | ( | QStringList | cmd, |
QStringList | env = QStringList() |
||
) | [slot] |
Convenient function to be used in the case where program doesn't expect stdin data or if you chose to directly close stdin without writing anything to it.
Definition at line 132 of file klfblockprocess.cpp.
References startProcess().