• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

KProcess Class Reference

Child process invocation, monitoring and control. More...

#include <kprocess.h>

Inheritance diagram for KProcess:
Inheritance graph
[legend]

List of all members.

Public Types

enum  OutputChannelMode {
  SeparateChannels = QProcess::SeparateChannels, MergedChannels = QProcess::MergedChannels, ForwardedChannels = QProcess::ForwardedChannels, OnlyStdoutChannel,
  OnlyStderrChannel
}

Public Member Functions

 KProcess (QObject *parent=0)
virtual ~KProcess ()
void setOutputChannelMode (OutputChannelMode mode)
OutputChannelMode outputChannelMode () const
void setNextOpenMode (QIODevice::OpenMode mode)
void setEnv (const QString &name, const QString &value, bool overwrite=true)
void unsetEnv (const QString &name)
void clearEnvironment ()
void setProgram (const QString &exe, const QStringList &args=QStringList())
void setProgram (const QStringList &argv)
KProcess & operator<< (const QString &arg)
KProcess & operator<< (const QStringList &args)
void clearProgram ()
void setShellCommand (const QString &cmd)
QStringList program () const
void start ()
int execute (int msecs=-1)
int startDetached ()
int pid () 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)

Protected Member Functions

 KProcess (KProcessPrivate *d, QObject *parent)

Protected Attributes

KProcessPrivate *const d_ptr

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. This is the preferred way of spawning child processes in KDE; don't use QProcess directly.

Author:
Oswald Buddenhagen <ossi@kde.org>

Definition at line 42 of file kprocess.h.


Member Enumeration Documentation

enum KProcess::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 

...

and the other way round

Definition at line 52 of file kprocess.h.


Constructor & Destructor Documentation

KProcess::KProcess ( QObject *  parent = 0  )  [explicit]

Constructor.

Definition at line 86 of file kprocess.cpp.

KProcess::~KProcess (  )  [virtual]

Destructor.

Definition at line 102 of file kprocess.cpp.

KProcess::KProcess ( KProcessPrivate *  d,
QObject *  parent 
) [protected]

Definition at line 94 of file kprocess.cpp.


Member Function Documentation

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 144 of file kprocess.cpp.

void KProcess::clearProgram (  ) 

Clear the program and command line argument list.

Definition at line 228 of file kprocess.cpp.

int KProcess::execute ( const QString &  exe,
const QStringList &  args = QStringList(),
int  msecs = -1 
) [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 312 of file kprocess.cpp.

int KProcess::execute ( const QStringList &  argv,
int  msecs = -1 
) [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 320 of file kprocess.cpp.

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: start(); waitForFinished(msecs); return exitCode();

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 300 of file kprocess.cpp.

KProcess & KProcess::operator<< ( const QString &  arg  ) 

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:

  KProcess p;
  p << "ls" << "-l" << "/usr/local/bin";
  ...

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 206 of file kprocess.cpp.

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 217 of file kprocess.cpp.

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 128 of file kprocess.cpp.

int KProcess::pid (  )  const

Obtain the process' ID as known to the system.

Unlike with QProcess::pid(), this is a real PID also on Windows.

This function can be called only while the process is running. It cannot be applied to detached processes.

Returns:
the process ID

Definition at line 354 of file kprocess.cpp.

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 284 of file kprocess.cpp.

void KProcess::setEnv ( const QString &  name,
const QString &  value,
bool  overwrite = true 
)

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 149 of file kprocess.cpp.

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 135 of file kprocess.cpp.

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 107 of file kprocess.cpp.

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 197 of file kprocess.cpp.

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 189 of file kprocess.cpp.

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.

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 236 of file kprocess.cpp.

void KProcess::start (  ) 

Start the process.

See also:
QProcess::start(const QString &, const QStringList &, OpenMode)

Definition at line 293 of file kprocess.cpp.

int KProcess::startDetached ( const QStringList &  argv  )  [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 347 of file kprocess.cpp.

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 327 of file kprocess.cpp.

int KProcess::startDetached ( const QString &  exe,
const QStringList &  args = QStringList() 
) [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

Reimplemented from QProcess.

Definition at line 338 of file kprocess.cpp.

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 170 of file kprocess.cpp.


Member Data Documentation

KProcessPrivate* const KProcess::d_ptr [protected]

Definition at line 321 of file kprocess.h.


The documentation for this class was generated from the following files:
  • kprocess.h
  • kprocess.cpp

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  • KJSEmbed
  •   WTF
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal