KProcess
#include <KProcess>
Public Types | |
enum | OutputChannelMode { SeparateChannels = QProcess::SeparateChannels , MergedChannels = QProcess::MergedChannels , ForwardedChannels = QProcess::ForwardedChannels , OnlyStdoutChannel = QProcess::ForwardedErrorChannel , OnlyStderrChannel = QProcess::ForwardedOutputChannel } |
Public Types inherited from QProcess | |
typedef | CreateProcessArgumentModifier |
enum | ExitStatus |
enum | InputChannelMode |
enum | ProcessChannel |
enum | ProcessChannelMode |
enum | ProcessError |
enum | ProcessState |
enum | UnixProcessFlag |
typedef | UnixProcessFlags |
Public Types inherited from QObject | |
typedef | QObjectList |
Public Types inherited from QIODeviceBase | |
typedef | OpenMode |
enum | OpenModeFlag |
Public Member Functions | |
KProcess (QObject *parent=nullptr) | |
~KProcess () override | |
void | clearEnvironment () |
void | clearProgram () |
int | execute (int msecs=-1) |
KProcess & | operator<< (const QString &arg) |
KProcess & | operator<< (const QStringList &args) |
OutputChannelMode | outputChannelMode () const |
QStringList | program () const |
void | setEnv (const QString &name, const QString &value, bool overwrite=true) |
void | setNextOpenMode (QIODevice::OpenMode mode) |
void | setOutputChannelMode (OutputChannelMode mode) |
void | setProgram (const QString &exe, const QStringList &args=QStringList()) |
void | setProgram (const QStringList &argv) |
void | setShellCommand (const QString &cmd) |
void | start () |
int | startDetached () |
void | unsetEnv (const QString &name) |
Public Member Functions inherited from QProcess | |
QProcess (QObject *parent) | |
QStringList | arguments () const const |
virtual qint64 | bytesToWrite () const const override |
std::function< void()> | childProcessModifier ()> childProcessModifier() const const |
virtual void | close () override |
void | closeReadChannel (ProcessChannel channel) |
void | closeWriteChannel () |
CreateProcessArgumentModifier | createProcessArgumentsModifier () const const |
QStringList | environment () const const |
QProcess::ProcessError | error () const const |
void | errorOccurred (QProcess::ProcessError error) |
int | exitCode () const const |
QProcess::ExitStatus | exitStatus () const const |
void | finished (int exitCode, QProcess::ExitStatus exitStatus) |
InputChannelMode | inputChannelMode () const const |
virtual bool | isSequential () const const override |
void | kill () |
QString | nativeArguments () const const |
virtual bool | open (OpenMode mode) override |
ProcessChannelMode | processChannelMode () const const |
QProcessEnvironment | processEnvironment () const const |
qint64 | processId () const const |
QString | program () const const |
QByteArray | readAllStandardError () |
QByteArray | readAllStandardOutput () |
ProcessChannel | readChannel () const const |
void | readyReadStandardError () |
void | readyReadStandardOutput () |
void | setArguments (const QStringList &arguments) |
void | setChildProcessModifier (const std::function< void()> &modifier) |
void | setCreateProcessArgumentsModifier (CreateProcessArgumentModifier modifier) |
void | setEnvironment (const QStringList &environment) |
void | setInputChannelMode (InputChannelMode mode) |
void | setNativeArguments (const QString &arguments) |
void | setProcessChannelMode (ProcessChannelMode mode) |
void | setProcessEnvironment (const QProcessEnvironment &environment) |
void | setProgram (const QString &program) |
void | setReadChannel (ProcessChannel channel) |
void | setStandardErrorFile (const QString &fileName, OpenMode mode) |
void | setStandardInputFile (const QString &fileName) |
void | setStandardOutputFile (const QString &fileName, OpenMode mode) |
void | setStandardOutputProcess (QProcess *destination) |
void | setUnixProcessParameters (const UnixProcessParameters ¶ms) |
void | setUnixProcessParameters (UnixProcessFlags flagsOnly) |
void | setWorkingDirectory (const QString &dir) |
void | start (const QString &program, const QStringList &arguments, OpenMode mode) |
void | start (OpenMode mode) |
void | startCommand (const QString &command, OpenMode mode) |
bool | startDetached (qint64 *pid) |
void | started () |
QProcess::ProcessState | state () const const |
void | stateChanged (QProcess::ProcessState newState) |
void | terminate () |
UnixProcessParameters | unixProcessParameters () const const |
virtual bool | waitForBytesWritten (int msecs) override |
bool | waitForFinished (int msecs) |
virtual bool | waitForReadyRead (int msecs) override |
bool | waitForStarted (int msecs) |
QString | workingDirectory () const const |
Public Member Functions inherited from QIODevice | |
QIODevice (QObject *parent) | |
void | aboutToClose () |
virtual bool | atEnd () const const |
virtual qint64 | bytesAvailable () const const |
void | bytesWritten (qint64 bytes) |
virtual bool | canReadLine () const const |
void | channelBytesWritten (int channel, qint64 bytes) |
void | channelReadyRead (int channel) |
void | commitTransaction () |
int | currentReadChannel () const const |
int | currentWriteChannel () const const |
QString | errorString () const const |
bool | getChar (char *c) |
bool | isOpen () const const |
bool | isReadable () const const |
bool | isTextModeEnabled () const const |
bool | isTransactionStarted () const const |
bool | isWritable () const const |
QIODeviceBase::OpenMode | openMode () const const |
qint64 | peek (char *data, qint64 maxSize) |
QByteArray | peek (qint64 maxSize) |
virtual qint64 | pos () const const |
bool | putChar (char c) |
qint64 | read (char *data, qint64 maxSize) |
QByteArray | read (qint64 maxSize) |
QByteArray | readAll () |
int | readChannelCount () const const |
void | readChannelFinished () |
qint64 | readLine (char *data, qint64 maxSize) |
QByteArray | readLine (qint64 maxSize) |
void | readyRead () |
virtual bool | reset () |
void | rollbackTransaction () |
virtual bool | seek (qint64 pos) |
void | setCurrentReadChannel (int channel) |
void | setCurrentWriteChannel (int channel) |
void | setTextModeEnabled (bool enabled) |
virtual qint64 | size () const const |
qint64 | skip (qint64 maxSize) |
void | startTransaction () |
void | ungetChar (char c) |
qint64 | write (const char *data) |
qint64 | write (const char *data, qint64 maxSize) |
qint64 | write (const QByteArray &data) |
int | writeChannelCount () const const |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QBindable< QString > | bindableObjectName () |
bool | blockSignals (bool block) |
const QObjectList & | children () const const |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectInfo () const const |
void | dumpObjectTree () const const |
QList< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (Qt::FindChildOptions options) const const |
bool | inherits (const char *className) const const |
void | installEventFilter (QObject *filterObj) |
bool | isQuickItemType () const const |
bool | isWidgetType () const const |
bool | isWindowType () const const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
QVariant | property (const char *name) const const |
Q_CLASSINFO (Name, Value) | |
Q_EMIT Q_EMIT | |
Q_ENUM (...) | |
Q_ENUM_NS (...) | |
Q_ENUMS (...) | |
Q_FLAG (...) | |
Q_FLAG_NS (...) | |
Q_FLAGS (...) | |
Q_GADGET Q_GADGET | |
Q_GADGET_EXPORT (EXPORT_MACRO) | |
Q_INTERFACES (...) | |
Q_INVOKABLE Q_INVOKABLE | |
Q_MOC_INCLUDE Q_MOC_INCLUDE | |
Q_NAMESPACE Q_NAMESPACE | |
Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
Q_OBJECT Q_OBJECT | |
Q_PROPERTY (...) | |
Q_REVISION Q_REVISION | |
Q_SET_OBJECT_NAME (Object) | |
Q_SIGNAL Q_SIGNAL | |
Q_SIGNALS Q_SIGNALS | |
Q_SLOT Q_SLOT | |
Q_SLOTS Q_SLOTS | |
T | qobject_cast (const QObject *object) |
T | qobject_cast (QObject *object) |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setObjectName (QAnyStringView name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | setProperty (const char *name, QVariant &&value) |
bool | signalsBlocked () const const |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType) |
QThread * | thread () const const |
Static Public Member Functions | |
static int | execute (const QString &exe, const QStringList &args=QStringList(), int msecs=-1) |
static int | execute (const QStringList &argv, int msecs=-1) |
static int | startDetached (const QString &exe, const QStringList &args=QStringList()) |
static int | startDetached (const QStringList &argv) |
Static Public Member Functions inherited from QProcess | |
int | execute (const QString &program, const QStringList &arguments) |
QString | nullDevice () |
QStringList | splitCommand (QStringView command) |
bool | startDetached (const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) |
QStringList | systemEnvironment () |
Static Public Member Functions inherited from QObject | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
Protected Member Functions | |
KCOREADDONS_NO_EXPORT | KProcess (KProcessPrivate *d, QObject *parent) |
Protected Member Functions inherited from QProcess | |
virtual qint64 | readData (char *data, qint64 maxlen) override |
void | setProcessState (ProcessState state) |
Protected Member Functions inherited from QIODevice | |
virtual qint64 | readLineData (char *data, qint64 maxSize) |
void | setErrorString (const QString &str) |
void | setOpenMode (QIODeviceBase::OpenMode openMode) |
virtual qint64 | skipData (qint64 maxSize) |
virtual qint64 | writeData (const char *data, qint64 maxSize)=0 |
Protected Member Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
bool | isSignalConnected (const QMetaMethod &signal) const const |
int | receivers (const char *signal) const const |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Protected Attributes | |
std::unique_ptr< KProcessPrivate > const | d_ptr |
Additional Inherited Members | |
Properties inherited from QObject | |
objectName | |
Public Attributes inherited from QProcess | |
CloseFileDescriptors | |
Crashed | |
CrashExit | |
FailedToStart | |
ForwardedChannels | |
ForwardedErrorChannel | |
ForwardedInputChannel | |
ForwardedOutputChannel | |
IgnoreSigPipe | |
ManagedInputChannel | |
MergedChannels | |
NormalExit | |
NotRunning | |
ReadError | |
ResetSignalHandlers | |
Running | |
SeparateChannels | |
StandardError | |
StandardOutput | |
Starting | |
Timedout | |
UnknownError | |
UseVFork | |
WriteError | |
Public Attributes inherited from QIODeviceBase | |
Append | |
ExistingOnly | |
NewOnly | |
NotOpen | |
ReadOnly | |
ReadWrite | |
Text | |
Truncate | |
Unbuffered | |
WriteOnly | |
Detailed Description
Child process invocation, monitoring and control.
This class extends QProcess by some useful functionality, overrides some defaults with saner values and wraps parts of the API into a more accessible one. Only use KProcess if you need the extra features, otherwise QProcess is the preferred way of spawning child processes.
Definition at line 33 of file kprocess.h.
Member Enumeration Documentation
◆ OutputChannelMode
Modes in which the output channels can be opened.
Enumerator | |
---|---|
SeparateChannels | Standard output and standard error are handled by KProcess as separate channels. |
MergedChannels | Standard output and standard error are handled by KProcess as one channel. |
ForwardedChannels | Both standard output and standard error are forwarded to the parent process' respective channel. |
OnlyStdoutChannel | Only standard output is handled; standard error is forwarded. |
OnlyStderrChannel | Only standard error is handled; standard output is forwarded. |
Definition at line 42 of file kprocess.h.
Constructor & Destructor Documentation
◆ KProcess() [1/2]
|
explicit |
Constructor.
Definition at line 27 of file kprocess.cpp.
◆ ~KProcess()
|
overridedefault |
Destructor.
◆ KProcess() [2/2]
|
protected |
Definition at line 34 of file kprocess.cpp.
Member Function Documentation
◆ clearEnvironment()
void KProcess::clearEnvironment | ( | ) |
Empties the process' environment.
Note that LD_LIBRARY_PATH/DYLD_LIBRARY_PATH is automatically added on *NIX.
This function must be called before starting the process.
Definition at line 63 of file kprocess.cpp.
◆ clearProgram()
void KProcess::clearProgram | ( | ) |
Clear the program and command line argument list.
Definition at line 159 of file kprocess.cpp.
◆ execute() [1/3]
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
exe the program to execute args the command line arguments for the program, one per list element msecs time to wait for process to exit before killing it
- Returns
- -2 if the process could not be started, -1 if it crashed, otherwise its exit code
Definition at line 261 of file kprocess.cpp.
◆ execute() [2/3]
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
argv the program to execute and the command line arguments for the program, one per list element msecs time to wait for process to exit before killing it
- Returns
- -2 if the process could not be started, -1 if it crashed, otherwise its exit code
Definition at line 269 of file kprocess.cpp.
◆ execute() [3/3]
int KProcess::execute | ( | int | msecs = -1 | ) |
Start the process, wait for it to finish, and return the exit code.
This method is roughly equivalent to the sequence:
Unlike the other execute() variants this method is not static, so the process can be parametrized properly and talked to.
- Parameters
-
msecs time to wait for process to exit before killing it
- Returns
- -2 if the process could not be started, -1 if it crashed, otherwise its exit code
Definition at line 249 of file kprocess.cpp.
◆ operator<<() [1/2]
Append an element to the command line argument list for this process.
If no executable is set yet, it will be set instead.
For example, doing an "ls -l /usr/local/bin" can be achieved by:
This function must be called before starting the process, obviously.
- Parameters
-
arg the argument to add
- Returns
- a reference to this KProcess
Definition at line 139 of file kprocess.cpp.
◆ operator<<() [2/2]
KProcess & KProcess::operator<< | ( | const QStringList & | args | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
args the arguments to add
- Returns
- a reference to this KProcess
Definition at line 149 of file kprocess.cpp.
◆ outputChannelMode()
KProcess::OutputChannelMode KProcess::outputChannelMode | ( | ) | const |
Query how the output channels of the child process are handled.
- Returns
- the output channel handling mode
Definition at line 49 of file kprocess.cpp.
◆ program()
QStringList KProcess::program | ( | ) | const |
Obtain the currently set program and arguments.
- Returns
- a list, the first element being the program, the remaining ones being command line arguments to the program.
Definition at line 235 of file kprocess.cpp.
◆ setEnv()
Adds the variable name
to the process' environment.
This function must be called before starting the process.
- Parameters
-
name the name of the environment variable value the new value for the environment variable overwrite if false
and the environment variable is already set, the old value will be preserved
Definition at line 68 of file kprocess.cpp.
◆ setNextOpenMode()
void KProcess::setNextOpenMode | ( | QIODevice::OpenMode | mode | ) |
Set the QIODevice open mode the process will be opened in.
This function must be called before starting the process, obviously.
- Parameters
-
mode the open mode. Note that this mode is automatically "reduced" according to the channel modes and redirections. The default is QIODevice::ReadWrite.
Definition at line 54 of file kprocess.cpp.
◆ setOutputChannelMode()
void KProcess::setOutputChannelMode | ( | OutputChannelMode | mode | ) |
Set how to handle the output channels of the child process.
The default is ForwardedChannels, which is unlike in QProcess. Do not request more than you actually handle, as this output is simply lost otherwise.
This function must be called before starting the process.
- Parameters
-
mode the output channel handling mode
Definition at line 44 of file kprocess.cpp.
◆ setProgram() [1/2]
void KProcess::setProgram | ( | const QString & | exe, |
const QStringList & | args = QStringList() ) |
Set the program and the command line arguments.
This function must be called before starting the process, obviously.
- Parameters
-
exe the program to execute args the command line arguments for the program, one per list element
Definition at line 114 of file kprocess.cpp.
◆ setProgram() [2/2]
void KProcess::setProgram | ( | const QStringList & | argv | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
argv the program to execute and the command line arguments for the program, one per list element
Definition at line 123 of file kprocess.cpp.
◆ setShellCommand()
void KProcess::setShellCommand | ( | const QString & | cmd | ) |
Set a command to execute through a shell (a POSIX sh on *NIX and cmd.exe on Windows).
Using this for anything but user-supplied commands is usually a bad idea, as the command's syntax depends on the platform. Redirections including pipes, etc. are better handled by the respective functions provided by QProcess.
If KProcess determines that the command does not really need a shell, it will transparently execute it without one for performance reasons.
This function must be called before starting the process, obviously.
- Parameters
-
cmd the command to execute through a shell. The caller must make sure that all filenames etc. are properly quoted when passed as argument. Failure to do so often results in serious security holes. See KShell::quoteArg().
Definition at line 176 of file kprocess.cpp.
◆ start()
void KProcess::start | ( | ) |
Start the process.
Definition at line 242 of file kprocess.cpp.
◆ startDetached() [1/3]
int KProcess::startDetached | ( | ) |
Start the process and detach from it.
See QProcess::startDetached() for details.
Unlike the other startDetached() variants this method is not static, so the process can be parametrized properly.
- Note
- Currently, only the setProgram()/setShellCommand() and setWorkingDirectory() parametrizations are supported.
The KProcess object may be re-used immediately after calling this function.
- Returns
- the PID of the started process or 0 on error
Definition at line 276 of file kprocess.cpp.
◆ startDetached() [2/3]
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
exe the program to start args the command line arguments for the program, one per list element
- Returns
- the PID of the started process or 0 on error
Definition at line 286 of file kprocess.cpp.
◆ startDetached() [3/3]
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
argv the program to start and the command line arguments for the program, one per list element
- Returns
- the PID of the started process or 0 on error
Definition at line 296 of file kprocess.cpp.
◆ unsetEnv()
void KProcess::unsetEnv | ( | const QString & | name | ) |
Removes the variable name
from the process' environment.
This function must be called before starting the process.
- Parameters
-
name the name of the environment variable
Definition at line 92 of file kprocess.cpp.
Member Data Documentation
◆ d_ptr
|
protected |
Definition at line 304 of file kprocess.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.