.TH "KProcess" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KProcess \- Child process invocation, monitoring and control.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <kprocess.h>\fP
.PP
Inherits \fBQObject\fP.
.PP
Inherited by \fBKProcIO\fP, and \fBKShellProcess\fP.
.PP
.SS "Public Types"

.in +1c
.ti -1c
.RI "enum \fBCommunication\fP { \fBNoCommunication\fP =  0, \fBStdin\fP =  1, \fBStdout\fP =  2, \fBStderr\fP =  4, \fBAllOutput\fP =  6, \fBAll\fP =  7, \fBNoRead\fP }"
.br
.ti -1c
.RI "enum \fBRunMode\fP { \fBDontCare\fP, \fBNotifyOnExit\fP, \fBBlock\fP, \fBOwnGroup\fP }"
.br
.ti -1c
.RI "enum { \fBPrioLowest\fP =  20, \fBPrioLow\fP =  10, \fBPrioLower\fP =  5, \fBPrioNormal\fP =  0, \fBPrioHigher\fP =  -5, \fBPrioHigh\fP =  -10, \fBPrioHighest\fP =  -19 }"
.br
.in -1c
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBprocessExited\fP (\fBKProcess\fP *proc)"
.br
.ti -1c
.RI "void \fBreceivedStdout\fP (\fBKProcess\fP *proc, char *buffer, int buflen)"
.br
.ti -1c
.RI "void \fBreceivedStdout\fP (int fd, int &len)"
.br
.ti -1c
.RI "void \fBreceivedStderr\fP (\fBKProcess\fP *proc, char *buffer, int buflen)"
.br
.ti -1c
.RI "void \fBwroteStdin\fP (\fBKProcess\fP *proc)"
.br
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKProcess\fP (\fBQObject\fP *\fBparent\fP, const char *\fBname\fP=0)"
.br
.ti -1c
.RI "\fBKProcess\fP ()"
.br
.ti -1c
.RI "virtual \fB~KProcess\fP ()"
.br
.ti -1c
.RI "bool \fBsetExecutable\fP (const \fBQString\fP &proc) KDE_DEPRECATED"
.br
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const \fBQString\fP &arg)"
.br
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const char *arg)"
.br
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const \fBQCString\fP &arg)"
.br
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const \fBQStringList\fP &args)"
.br
.ti -1c
.RI "void \fBclearArguments\fP ()"
.br
.ti -1c
.RI "virtual bool \fBstart\fP (\fBRunMode\fP runmode=NotifyOnExit, \fBCommunication\fP comm=NoCommunication)"
.br
.ti -1c
.RI "virtual bool \fBkill\fP (int signo=SIGTERM)"
.br
.ti -1c
.RI "bool \fBisRunning\fP () const "
.br
.ti -1c
.RI "pid_t \fBpid\fP () const "
.br
.ti -1c
.RI "KDE_DEPRECATED pid_t \fBgetPid\fP () const "
.br
.ti -1c
.RI "void \fBsuspend\fP ()"
.br
.ti -1c
.RI "void \fBresume\fP ()"
.br
.ti -1c
.RI "bool \fBwait\fP (int timeout=-1)"
.br
.ti -1c
.RI "bool \fBnormalExit\fP () const "
.br
.ti -1c
.RI "bool \fBsignalled\fP () const "
.br
.ti -1c
.RI "bool \fBcoreDumped\fP () const "
.br
.ti -1c
.RI "int \fBexitStatus\fP () const "
.br
.ti -1c
.RI "int \fBexitSignal\fP () const "
.br
.ti -1c
.RI "bool \fBwriteStdin\fP (const char *buffer, int buflen)"
.br
.ti -1c
.RI "bool \fBcloseStdin\fP ()"
.br
.ti -1c
.RI "bool \fBcloseStdout\fP ()"
.br
.ti -1c
.RI "bool \fBcloseStderr\fP ()"
.br
.ti -1c
.RI "bool \fBclosePty\fP ()"
.br
.ti -1c
.RI "void \fBcloseAll\fP ()"
.br
.ti -1c
.RI "const \fBQValueList\fP< \fBQCString\fP > & \fBargs\fP ()"
.br
.ti -1c
.RI "void \fBsetRunPrivileged\fP (bool keepPrivileges)"
.br
.ti -1c
.RI "bool \fBrunPrivileged\fP () const "
.br
.ti -1c
.RI "void \fBsetEnvironment\fP (const \fBQString\fP &\fBname\fP, const \fBQString\fP &value)"
.br
.ti -1c
.RI "void \fBsetWorkingDirectory\fP (const \fBQString\fP &dir)"
.br
.ti -1c
.RI "void \fBsetUseShell\fP (bool useShell, const char *shell=0)"
.br
.ti -1c
.RI "void \fBdetach\fP ()"
.br
.ti -1c
.RI "bool \fBsetPriority\fP (int prio)"
.br
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "static \fBQString\fP \fBquote\fP (const \fBQString\fP &arg)"
.br
.in -1c
.SS "Protected Slots"

.in +1c
.ti -1c
.RI "void \fBslotChildOutput\fP (int fdno)"
.br
.ti -1c
.RI "void \fBslotChildError\fP (int fdno)"
.br
.ti -1c
.RI "void \fBslotSendData\fP (int dummy)"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "void \fBsetupEnvironment\fP ()"
.br
.ti -1c
.RI "virtual int \fBsetupCommunication\fP (\fBCommunication\fP comm)"
.br
.ti -1c
.RI "virtual int \fBcommSetupDoneP\fP ()"
.br
.ti -1c
.RI "virtual int \fBcommSetupDoneC\fP ()"
.br
.ti -1c
.RI "virtual void \fBprocessHasExited\fP (int state)"
.br
.ti -1c
.RI "virtual void \fBcommClose\fP ()"
.br
.ti -1c
.RI "void \fBsetBinaryExecutable\fP (const char *filename)"
.br
.ti -1c
.RI "int \fBchildOutput\fP (int fdno)"
.br
.ti -1c
.RI "int \fBchildError\fP (int fdno)"
.br
.ti -1c
.RI "virtual void \fBvirtual_hook\fP (int id, void *data)"
.br
.in -1c
.SS "Protected Attributes"

.in +1c
.ti -1c
.RI "\fBQValueList\fP< \fBQCString\fP > \fBarguments\fP"
.br
.ti -1c
.RI "\fBRunMode\fP \fBrun_mode\fP"
.br
.ti -1c
.RI "bool \fBruns\fP"
.br
.ti -1c
.RI "pid_t \fBpid_\fP"
.br
.ti -1c
.RI "int \fBstatus\fP"
.br
.ti -1c
.RI "bool \fBkeepPrivs\fP"
.br
.ti -1c
.RI "int \fBout\fP [2]"
.br
.ti -1c
.RI "int \fBin\fP [2]"
.br
.ti -1c
.RI "int \fBerr\fP [2]"
.br
.ti -1c
.RI "\fBQSocketNotifier\fP * \fBinnot\fP"
.br
.ti -1c
.RI "\fBQSocketNotifier\fP * \fBoutnot\fP"
.br
.ti -1c
.RI "\fBQSocketNotifier\fP * \fBerrnot\fP"
.br
.ti -1c
.RI "\fBCommunication\fP \fBcommunication\fP"
.br
.ti -1c
.RI "const char * \fBinput_data\fP"
.br
.ti -1c
.RI "int \fBinput_sent\fP"
.br
.ti -1c
.RI "int \fBinput_total\fP"
.br
.in -1c
.SS "Friends"

.in +1c
.ti -1c
.RI "class \fBKProcessController\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
Child process invocation, monitoring and control. 

\fBGeneral usage and features:\fP
.br
.PP
This class allows a \fBKDE\fP application to start child processes without having to worry about UN*X signal handling issues and zombie process reaping.
.PP
\fBSee also:\fP
.RS 4
\fBKProcIO\fP
.RE
.PP
Basically, this class distinguishes three different ways of running child processes:
.PP
.PD 0
.IP "\(bu" 2
DontCare -- The child process is invoked and both the child process and the parent process continue concurrently.
.PP
The process is started in an own session (see setsid(2)).
.PP
.PD 0
.IP "\(bu" 2
NotifyOnExit -- The child process is invoked and both the child and the parent process run concurrently.
.PP
When the child process exits, the KProcess instance corresponding to it emits the \fBQt\fP signal \fBprocessExited()\fP. Since this signal is \fInot\fP emitted from within a UN*X signal handler, arbitrary function calls can be made.
.PP
Be aware: When the KProcess object gets destructed, the child process will be killed if it is still running! This means in particular, that it usually makes no sense to use a KProcess on the stack with NotifyOnExit.
.PP
.PD 0
.IP "\(bu" 2
OwnGroup -- like NotifyOnExit, but the child process is started in an own process group (and an own session, FWIW). The behavior of \fBkill()\fP changes to killing the whole process group - this makes this mode useful for implementing primitive job management. It can be used to work around broken wrapper scripts that don't propagate signals to the 'real' program. However, use this with care, as you disturb the shell's job management if your program is started from the command line.
.PP
.PD 0
.IP "\(bu" 2
Block -- The child process starts and the parent process is suspended until the child process exits. (\fIReally\fP not recommended for programs with a GUI.) In this mode the parent can read the child's output, but can't send it any input.
.PP
KProcess also provides several functions for determining the exit status and the pid of the child process it represents.
.PP
Furthermore it is possible to supply command-line arguments to the process in a clean fashion (no null-terminated stringlists and such...)
.PP
A small usage example: 
.PP
.nf
   KProcess *proc = new KProcess;

   *proc << 'my_executable';
   *proc << 'These' << 'are' << 'the' << 'command' << 'line' << 'args';
   QApplication::connect(proc, SIGNAL(processExited(KProcess *)),
                         pointer_to_my_object, SLOT(my_objects_slot(KProcess *)));
   proc->start();

.fi
.PP
.PP
This will start 'my_executable' with the commandline arguments 'These'...
.PP
When the child process exits, the slot will be invoked.
.PP
\fBCommunication with the child process:\fP
.br
.PP
KProcess supports communication with the child process through stdin/stdout/stderr.
.PP
The following functions are provided for getting data from the child process or sending data to the child's stdin (For more information, have a look at the documentation of each function):
.PP
.PD 0
.IP "\(bu" 2
\fBwriteStdin()\fP -- Transmit data to the child process' stdin. When all data was sent, the signal \fBwroteStdin()\fP is emitted.
.PP
.PD 0
.IP "\(bu" 2
When data arrives at stdout or stderr, the signal \fBreceivedStdout()\fP resp. \fBreceivedStderr()\fP is emitted.
.PP
.PD 0
.IP "\(bu" 2
You can shut down individual communication channels with \fBcloseStdin()\fP, \fBcloseStdout()\fP, and \fBcloseStderr()\fP, resp.
.PP
\fBAuthor:\fP
.RS 4
Christian Czezatke e9025461@student.tuwien.ac.at 
.RE
.PP

.PP
Definition at line 124 of file kprocess.h.
.SH "Member Enumeration Documentation"
.PP 
.SS "enum \fBKProcess::Communication\fP"
.PP
Modes in which the communication channel can be opened. 
.PP
If communication for more than one channel is required, the values have to be or'ed together, for example to get communication with stdout as well as with stdin, you would specify \fCStdin\fP | \fCStdout\fP 
.PP
If \fCNoRead\fP is specified in conjunction with \fCStdout\fP, no data is actually read from \fCStdout\fP but only the signal \fBreceivedStdout(int fd, int &len)\fP is emitted. 
.PP
Definition at line 142 of file kprocess.h.
.SS "enum \fBKProcess::RunMode\fP"
.PP
Run-modes for a child process. 
.PP
\fBEnumeration values: \fP
.in +1c
.TP
\fB\fIDontCare \fP\fP
The application does not receive notifications from the subprocess when it is finished or aborted. 
.TP
\fB\fINotifyOnExit \fP\fP
The application is notified when the subprocess dies. 
.TP
\fB\fIBlock \fP\fP
The application is suspended until the started process is finished. 
.TP
\fB\fIOwnGroup \fP\fP
Same as NotifyOnExit, but the process is run in an own session, just like with DontCare. 
.PP
Definition at line 152 of file kprocess.h.
.SS "anonymous enum"
.PP
More or less intuitive constants for use with \fBsetPriority()\fP. 
.PP
Definition at line 552 of file kprocess.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KProcess::KProcess (\fBQObject\fP * parent, const char * name = \fC0\fP)"
.PP
Constructor 
.PP
\fBSince:\fP
.RS 4
3.2. 
.RE
.PP

.PP
Definition at line 120 of file kprocess.cpp.
.PP
References KProcessController::addKProcess(), err, in, out, and KProcessController::ref().
.SS "KProcess::KProcess ()"
.PP
Constructor. 
.PP
Definition at line 145 of file kprocess.cpp.
.PP
References KProcessController::addKProcess(), err, in, out, and KProcessController::ref().
.SS "KProcess::~\fBKProcess\fP ()\fC [virtual]\fP"
.PP
Destructor:. 
.PP
If the process is running when the destructor for this class is called, the child process is killed with a SIGKILL, but only if the run mode is not of type \fCDontCare\fP. Processes started as \fCDontCare\fP keep running anyway. 
.PP
Definition at line 225 of file kprocess.cpp.
.PP
References KProcessController::deref(), detach(), DontCare, kill(), KProcessController::removeKProcess(), and run_mode.
.SH "Member Function Documentation"
.PP 
.SS "bool KProcess::setExecutable (const \fBQString\fP & proc)"
.PP
\fBDeprecated\fP
.RS 4
Use operator<< instead. 
.RE
.PP
Sets the executable to be started with this KProcess object. Returns false if the process is currently running (in that case the executable remains unchanged).
.PP
\fBSee also:\fP
.RS 4
operator<< 
.RE
.PP

.PP
Definition at line 255 of file kprocess.cpp.
.PP
References arguments, QValueList::begin(), QValueList::isEmpty(), QValueList::prepend(), QValueList::remove(), and runs.
.SS "\fBKProcess\fP & KProcess::operator<< (const \fBQString\fP & arg)"
.PP
Sets the executable and the command line argument list for this process. 
.PP
For example, doing an 'ls -l /usr/local/bin' can be achieved by: 
.PP
.nf
  KProcess p;
  ...
  p << 'ls' << '-l' << '/usr/local/bin'

.fi
.PP
.PP
\fBParameters:\fP
.RS 4
\fIarg\fP the argument to add 
.RE
.PP
\fBReturns:\fP
.RS 4
a reference to this KProcess 
.RE
.PP

.PP
Definition at line 287 of file kprocess.cpp.
.PP
References QValueList::append(), and arguments.
.PP
Referenced by operator<<().
.SS "\fBKProcess\fP & KProcess::operator<< (const char * arg)"
.PP
Similar to previous method, takes a char *, supposed to be in locale 8 bit already. 
.PP
Definition at line 281 of file kprocess.cpp.
.PP
References QValueList::append(), and arguments.
.SS "\fBKProcess\fP & KProcess::operator<< (const \fBQCString\fP & arg)"
.PP
Similar to previous method, takes a \fBQCString\fP, supposed to be in locale 8 bit already. 
.PP
\fBParameters:\fP
.RS 4
\fIarg\fP the argument to add 
.RE
.PP
\fBReturns:\fP
.RS 4
a reference to this KProcess 
.RE
.PP

.PP
Definition at line 276 of file kprocess.cpp.
.PP
References operator<<().
.SS "\fBKProcess\fP & KProcess::operator<< (const \fBQStringList\fP & args)"
.PP
Sets the executable and the command line argument list for this process, in a single method call, or add a list of arguments. 
.PP
\fBParameters:\fP
.RS 4
\fIargs\fP the arguments to add 
.RE
.PP
\fBReturns:\fP
.RS 4
a reference to this KProcess 
.RE
.PP

.PP
Definition at line 268 of file kprocess.cpp.
.PP
References QValueList::append(), args(), arguments, QValueList::begin(), and QValueList::end().
.SS "void KProcess::clearArguments ()"
.PP
Clear a command line argument list that has been set by using operator<<. 
.PP
Definition at line 293 of file kprocess.cpp.
.PP
References arguments, and QValueList::clear().
.PP
Referenced by KProcIO::resetAll().
.SS "bool KProcess::start (\fBRunMode\fP runmode = \fCNotifyOnExit\fP, \fBCommunication\fP comm = \fCNoCommunication\fP)\fC [virtual]\fP"
.PP
Starts the process. 
.PP
For a detailed description of the various run modes and communication semantics, have a look at the general description of the KProcess class. Note that if you use setUsePty( Stdout | Stderr, <bool> ), you cannot use Stdout | Stderr here - instead, use Stdout only to receive the mixed output.
.PP
The following problems could cause this function to return false:
.PP
.PD 0
.IP "\(bu" 2
The process is already running. 
.IP "\(bu" 2
The command line argument list is empty. 
.IP "\(bu" 2
The the \fCcomm\fP parameter is incompatible with the selected pty usage. 
.IP "\(bu" 2
The starting of the process failed (could not fork). 
.IP "\(bu" 2
The executable was not found.
.PP
\fBParameters:\fP
.RS 4
\fIrunmode\fP The Run-mode for the process. 
.br
\fIcomm\fP Specifies which communication links should be established to the child process (stdin/stdout/stderr). By default, no communication takes place and the respective communication signals will never get emitted.
.RE
.PP
\fBReturns:\fP
.RS 4
true on success, false on error (see above for error conditions) 
.RE
.PP

.PP
Reimplemented in \fBKShellProcess\fP.
.PP
Definition at line 298 of file kprocess.cpp.
.PP
References arguments, Block, commClose(), commSetupDoneC(), commSetupDoneP(), QValueList::count(), DontCare, endl(), QApplication::flushX(), input_data, OwnGroup, pid_, processExited(), KProcessController::rescheduleCheck(), run_mode, runPrivileged(), runs, setupCommunication(), setupEnvironment(), status, and KProcessController::unscheduleCheck().
.PP
Referenced by KConfigBackEnd::checkConfigFilesWritable(), KProcIO::start(), and KShellProcess::start().
.SS "bool KProcess::kill (int signo = \fCSIGTERM\fP)\fC [virtual]\fP"
.PP
Stop the process (by sending it a signal). 
.PP
\fBParameters:\fP
.RS 4
\fIsigno\fP The signal to send. The default is SIGTERM. 
.RE
.PP
\fBReturns:\fP
.RS 4
true if the signal was delivered successfully. 
.RE
.PP

.PP
Definition at line 492 of file kprocess.cpp.
.PP
References OwnGroup, pid_, run_mode, and runs.
.PP
Referenced by KProcIO::resetAll(), and ~KProcess().
.SS "bool KProcess::isRunning () const"
.PP
Checks whether the process is running. 
.PP
\fBReturns:\fP
.RS 4
true if the process is (still) considered to be running 
.RE
.PP

.PP
Definition at line 503 of file kprocess.cpp.
.PP
References runs.
.PP
Referenced by KProcIO::resetAll().
.SS "pid_t KProcess::pid () const"
.PP
Returns the process id of the process. 
.PP
If it is called after the process has exited, it returns the process id of the last child process that was created by this instance of KProcess.
.PP
Calling it before any child process has been started by this KProcess instance causes \fBpid()\fP to return 0. 
.PP
\fBReturns:\fP
.RS 4
the pid of the process or 0 if no process has been started yet. 
.RE
.PP

.PP
Definition at line 510 of file kprocess.cpp.
.PP
References pid_.
.SS "KDE_DEPRECATED pid_t KProcess::getPid () const\fC [inline]\fP"
.PP
\fBDeprecated\fP
.RS 4
Use \fBpid()\fP instead. 
.RE
.PP

.PP
Definition at line 306 of file kprocess.h.
.SS "void KProcess::suspend ()"
.PP
Suspend processing of data from stdout of the child process. 
.PP
Definition at line 647 of file kprocess.cpp.
.PP
References outnot, and QSocketNotifier::setEnabled().
.PP
Referenced by commSetupDoneP().
.SS "void KProcess::resume ()"
.PP
Resume processing of data from stdout of the child process. 
.PP
Definition at line 653 of file kprocess.cpp.
.PP
References outnot, and QSocketNotifier::setEnabled().
.SS "bool KProcess::wait (int timeout = \fC-1\fP)"
.PP
Suspend execution of the current thread until the child process dies or the timeout hits. 
.PP
This function is not recommended for programs with a GUI. 
.PP
\fBParameters:\fP
.RS 4
\fItimeout\fP timeout in seconds. -1 means wait indefinitely. 
.RE
.PP
\fBReturns:\fP
.RS 4
true if the process exited, false if the timeout hit. 
.RE
.PP
\fBSince:\fP
.RS 4
3.2 
.RE
.PP

.PP
Definition at line 527 of file kprocess.cpp.
.PP
References KProcessController::notifierFd(), pid_, processHasExited(), KProcessController::rescheduleCheck(), runs, status, and KProcessController::unscheduleCheck().
.SS "bool KProcess::normalExit () const"
.PP
Checks whether the process exited cleanly. 
.PP
\fBReturns:\fP
.RS 4
true if the process has already finished and has exited 'voluntarily', ie: it has not been killed by a signal. 
.RE
.PP

.PP
Definition at line 593 of file kprocess.cpp.
.PP
References pid_, runs, and status.
.SS "bool KProcess::signalled () const"
.PP
Checks whether the process was killed by a signal. 
.PP
\fBReturns:\fP
.RS 4
true if the process has already finished and has not exited 'voluntarily', ie: it has been killed by a signal.
.RE
.PP
\fBSince:\fP
.RS 4
3.2 
.RE
.PP

.PP
Definition at line 599 of file kprocess.cpp.
.PP
References pid_, runs, and status.
.PP
Referenced by coreDumped().
.SS "bool KProcess::coreDumped () const"
.PP
Checks whether a killed process dumped core. 
.PP
\fBReturns:\fP
.RS 4
true if \fBsignalled()\fP returns true and the process dumped core. Note that on systems that don't define the WCOREDUMP macro, the return value is always false.
.RE
.PP
\fBSince:\fP
.RS 4
3.2 
.RE
.PP

.PP
Definition at line 605 of file kprocess.cpp.
.PP
References signalled(), and status.
.SS "int KProcess::exitStatus () const"
.PP
Returns the exit status of the process. 
.PP
\fBReturns:\fP
.RS 4
the exit status of the process. Note that this value is not valid if \fBnormalExit()\fP returns false. 
.RE
.PP

.PP
Definition at line 615 of file kprocess.cpp.
.PP
References status.
.SS "int KProcess::exitSignal () const"
.PP
Returns the signal the process was killed by. 
.PP
\fBReturns:\fP
.RS 4
the signal number that caused the process to exit. Note that this value is not valid if \fBsignalled()\fP returns false.
.RE
.PP
\fBSince:\fP
.RS 4
3.2 
.RE
.PP

.PP
Definition at line 621 of file kprocess.cpp.
.PP
References status.
.SS "bool KProcess::writeStdin (const char * buffer, int buflen)"
.PP
Transmit data to the child process' stdin. 
.PP
This function may return false in the following cases:
.PP
.PD 0
.IP "\(bu" 2
The process is not currently running. This implies that you cannot use this function in Block mode.
.PP
.PD 0
.IP "\(bu" 2
Communication to stdin has not been requested in the \fBstart()\fP call.
.PP
.PD 0
.IP "\(bu" 2
Transmission of data to the child process by a previous call to \fBwriteStdin()\fP is still in progress.
.PP
Please note that the data is sent to the client asynchronously, so when this function returns, the data might not have been processed by the child process. That means that you must not free \fCbuffer\fP or call \fBwriteStdin()\fP again until either a \fBwroteStdin()\fP signal indicates that the data has been sent or a \fBprocessExited()\fP signal shows that the child process is no longer alive.
.PP
If all the data has been sent to the client, the signal \fBwroteStdin()\fP will be emitted.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the buffer to write 
.br
\fIbuflen\fP the length of the buffer 
.RE
.PP
\fBReturns:\fP
.RS 4
false if an error has occurred 
.RE
.PP

.PP
Definition at line 627 of file kprocess.cpp.
.PP
References communication, innot, input_data, input_sent, input_total, QSocketNotifier::setEnabled(), and slotSendData().
.PP
Referenced by KProcIO::fputs(), and KProcIO::writeStdin().
.SS "bool KProcess::closeStdin ()"
.PP
Shuts down the Stdin communication link. 
.PP
If no pty is used, this causes 'EOF' to be indicated on the child's stdin file descriptor.
.PP
\fBReturns:\fP
.RS 4
false if no Stdin communication link exists (any more). 
.RE
.PP

.PP
Definition at line 659 of file kprocess.cpp.
.PP
References communication, in, and innot.
.PP
Referenced by closeAll(), KProcIO::closeWhenDone(), commClose(), and slotSendData().
.SS "bool KProcess::closeStdout ()"
.PP
Shuts down the Stdout communication link. 
.PP
If no pty is used, any further attempts by the child to write to its stdout file descriptor will cause it to receive a SIGPIPE.
.PP
\fBReturns:\fP
.RS 4
false if no Stdout communication link exists (any more). 
.RE
.PP

.PP
Definition at line 673 of file kprocess.cpp.
.PP
References communication, out, and outnot.
.PP
Referenced by closeAll(), commClose(), and slotChildOutput().
.SS "bool KProcess::closeStderr ()"
.PP
Shuts down the Stderr communication link. 
.PP
If no pty is used, any further attempts by the child to write to its stderr file descriptor will cause it to receive a SIGPIPE.
.PP
\fBReturns:\fP
.RS 4
false if no Stderr communication link exists (any more). 
.RE
.PP

.PP
Definition at line 687 of file kprocess.cpp.
.PP
References communication, err, and errnot.
.PP
Referenced by closeAll(), commClose(), and slotChildError().
.SS "bool KProcess::closePty ()"
.PP
Deletes the optional utmp entry and closes the pty. 
.PP
Make sure to shut down any communication links that are using the pty before calling this function.
.PP
\fBReturns:\fP
.RS 4
false if the pty is not open (any more). 
.RE
.PP

.PP
Definition at line 701 of file kprocess.cpp.
.PP
Referenced by closeAll(), and commClose().
.SS "void KProcess::closeAll ()"
.PP
Calls the above four close* functions in a row. 
.PP
Definition at line 716 of file kprocess.cpp.
.PP
References closePty(), closeStderr(), closeStdin(), and closeStdout().
.SS "const \fBQValueList\fP<\fBQCString\fP>& KProcess::args ()\fC [inline]\fP"
.PP
Lets you see what your arguments are for debugging. 
.PP
\fBReturns:\fP
.RS 4
the list of arguments 
.RE
.PP

.PP
Definition at line 450 of file kprocess.h.
.PP
Referenced by operator<<().
.SS "void KProcess::setRunPrivileged (bool keepPrivileges)"
.PP
Controls whether the started process should drop any setuid/setgid privileges or whether it should keep them. 
.PP
Note that this function is mostly a dummy, as the \fBKDE\fP libraries currently refuse to run with setuid/setgid privileges.
.PP
The default is false: drop privileges 
.PP
\fBParameters:\fP
.RS 4
\fIkeepPrivileges\fP true to keep the privileges 
.RE
.PP

.PP
Definition at line 198 of file kprocess.cpp.
.PP
References keepPrivs.
.SS "bool KProcess::runPrivileged () const"
.PP
Returns whether the started process will drop any setuid/setgid privileges or whether it will keep them. 
.PP
\fBReturns:\fP
.RS 4
true if the process runs privileged 
.RE
.PP

.PP
Definition at line 204 of file kprocess.cpp.
.PP
References keepPrivs.
.PP
Referenced by start().
.SS "void KProcess::setEnvironment (const \fBQString\fP & name, const \fBQString\fP & value)"
.PP
Adds the variable \fCname\fP to the process' environment. 
.PP
This function must be called before starting the process. 
.PP
\fBParameters:\fP
.RS 4
\fIname\fP the name of the environment variable 
.br
\fIvalue\fP the new value for the environment variable 
.RE
.PP

.PP
Definition at line 171 of file kprocess.cpp.
.SS "void KProcess::setWorkingDirectory (const \fBQString\fP & dir)"
.PP
Changes the current working directory (CWD) of the process to be started. 
.PP
This function must be called before starting the process. 
.PP
\fBParameters:\fP
.RS 4
\fIdir\fP the new directory 
.RE
.PP

.PP
Definition at line 177 of file kprocess.cpp.
.SS "void KProcess::setUseShell (bool useShell, const char * shell = \fC0\fP)"
.PP
Specify whether to start the command via a shell or directly. 
.PP
The default is to start the command directly. If \fCuseShell\fP is true \fCshell\fP will be used as shell, or if shell is empty, /bin/sh will be used.
.PP
When using a shell, the caller should make sure that all filenames etc. are properly quoted when passed as argument. 
.PP
\fBSee also:\fP
.RS 4
\fBquote()\fP 
.RE
.PP
\fBParameters:\fP
.RS 4
\fIuseShell\fP true if the command should be started via a shell 
.br
\fIshell\fP the path to the shell that will execute the process, or 0 to use /bin/sh. Use getenv('SHELL') to use the user's default shell, but note that doing so is usually a bad idea for shell compatibility reasons. 
.RE
.PP
\fBSince:\fP
.RS 4
3.1 
.RE
.PP

.PP
Definition at line 764 of file kprocess.cpp.
.PP
Referenced by KShellProcess::KShellProcess().
.SS "\fBQString\fP KProcess::quote (const \fBQString\fP & arg)\fC [static]\fP"
.PP
This function can be used to quote an argument string such that the shell processes it properly. 
.PP
This is e. g. necessary for user-provided file names which may contain spaces or quotes. It also prevents expansion of wild cards and environment variables. 
.PP
\fBParameters:\fP
.RS 4
\fIarg\fP the argument to quote 
.RE
.PP
\fBReturns:\fP
.RS 4
the quoted argument 
.RE
.PP
\fBSince:\fP
.RS 4
3.1 
.RE
.PP

.PP
Reimplemented in \fBKShellProcess\fP.
.PP
Definition at line 808 of file kprocess.cpp.
.PP
References QString::append(), QString::prepend(), and QString::replace().
.PP
Referenced by KShellProcess::quote(), and KTempDir::unlink().
.SS "void KProcess::detach ()"
.PP
Detaches KProcess from child process. 
.PP
All communication is closed. No exit notification is emitted any more for the child process. Deleting the KProcess will no longer kill the child process. Note that the current process remains the parent process of the child process. 
.PP
Definition at line 240 of file kprocess.cpp.
.PP
References KProcessController::addProcess(), commClose(), pid_, and runs.
.PP
Referenced by ~KProcess().
.SS "bool KProcess::setPriority (int prio)"
.PP
Sets the scheduling priority of the process. 
.PP
\fBParameters:\fP
.RS 4
\fIprio\fP the new priority in the range -20 (high) to 19 (low). 
.RE
.PP
\fBReturns:\fP
.RS 4
false on error; see setpriority(2) for possible reasons. 
.RE
.PP
\fBSince:\fP
.RS 4
3.2 
.RE
.PP

.PP
Definition at line 210 of file kprocess.cpp.
.PP
References pid_, and runs.
.SS "void KProcess::processExited (\fBKProcess\fP * proc)\fC [signal]\fP"
.PP
Emitted after the process has terminated when the process was run in the \fCNotifyOnExit\fP (==default option to \fBstart()\fP ) or the Block mode. 
.PP
\fBParameters:\fP
.RS 4
\fIproc\fP a pointer to the process that has exited 
.RE
.PP

.PP
Referenced by processHasExited(), and start().
.SS "void KProcess::receivedStdout (\fBKProcess\fP * proc, char * buffer, int buflen)\fC [signal]\fP"
.PP
Emitted, when output from the child process has been received on stdout. 
.PP
To actually get this signal, the Stdout communication link has to be turned on in \fBstart()\fP.
.PP
\fBParameters:\fP
.RS 4
\fIproc\fP a pointer to the process that has received the output 
.br
\fIbuffer\fP The data received. 
.br
\fIbuflen\fP The number of bytes that are available.
.RE
.PP
You should copy the information contained in \fCbuffer\fP to your private data structures before returning from the slot. Example: 
.PP
.nf
     QString myBuf = QString::fromLatin1(buffer, buflen);

.fi
.PP
 
.PP
Referenced by childOutput().
.SS "void KProcess::receivedStdout (int fd, int & len)\fC [signal]\fP"
.PP
Emitted when output from the child process has been received on stdout. 
.PP
To actually get this signal, the Stdout communication link has to be turned on in \fBstart()\fP and the NoRead flag must have been passed.
.PP
You will need to explicitly call \fBresume()\fP after your call to \fBstart()\fP to begin processing data from the child process' stdout. This is to ensure that this signal is not emitted when no one is connected to it, otherwise this signal will not be emitted.
.PP
The data still has to be read from file descriptor \fCfd\fP. 
.PP
\fBParameters:\fP
.RS 4
\fIfd\fP the file descriptor that provides the data 
.br
\fIlen\fP the number of bytes that have been read from \fCfd\fP must be written here 
.RE
.PP

.SS "void KProcess::receivedStderr (\fBKProcess\fP * proc, char * buffer, int buflen)\fC [signal]\fP"
.PP
Emitted, when output from the child process has been received on stderr. 
.PP
To actually get this signal, the Stderr communication link has to be turned on in \fBstart()\fP.
.PP
You should copy the information contained in \fCbuffer\fP to your private data structures before returning from the slot.
.PP
\fBParameters:\fP
.RS 4
\fIproc\fP a pointer to the process that has received the data 
.br
\fIbuffer\fP The data received. 
.br
\fIbuflen\fP The number of bytes that are available. 
.RE
.PP

.PP
Referenced by childError().
.SS "void KProcess::wroteStdin (\fBKProcess\fP * proc)\fC [signal]\fP"
.PP
Emitted after all the data that has been specified by a prior call to \fBwriteStdin()\fP has actually been written to the child process. 
.PP
\fBParameters:\fP
.RS 4
\fIproc\fP a pointer to the process 
.RE
.PP

.PP
Referenced by KProcIO::resetAll(), slotSendData(), and KProcIO::start().
.SS "void KProcess::slotChildOutput (int fdno)\fC [protected, slot]\fP"
.PP
This slot gets activated when data from the child's stdout arrives. 
.PP
It usually calls \fBchildOutput()\fP. 
.PP
\fBParameters:\fP
.RS 4
\fIfdno\fP the file descriptor for the output 
.RE
.PP

.PP
Definition at line 730 of file kprocess.cpp.
.PP
References childOutput(), and closeStdout().
.PP
Referenced by commClose(), and commSetupDoneP().
.SS "void KProcess::slotChildError (int fdno)\fC [protected, slot]\fP"
.PP
This slot gets activated when data from the child's stderr arrives. 
.PP
It usually calls \fBchildError()\fP. 
.PP
\fBParameters:\fP
.RS 4
\fIfdno\fP the file descriptor for the output 
.RE
.PP

.PP
Definition at line 737 of file kprocess.cpp.
.PP
References childError(), and closeStderr().
.PP
Referenced by commClose(), and commSetupDoneP().
.SS "void KProcess::slotSendData (int dummy)\fC [protected, slot]\fP"
.PP
Called when another bulk of data can be sent to the child's stdin. 
.PP
If there is no more data to be sent to stdin currently available, this function must disable the \fBQSocketNotifier\fP innot. 
.PP
\fBParameters:\fP
.RS 4
\fIdummy\fP ignore this argument 
.RE
.PP

.PP
Definition at line 744 of file kprocess.cpp.
.PP
References closeStdin(), endl(), in, innot, input_data, input_sent, input_total, QSocketNotifier::setEnabled(), and wroteStdin().
.PP
Referenced by commSetupDoneP(), and writeStdin().
.SS "void KProcess::setupEnvironment ()\fC [protected]\fP"
.PP
Sets up the environment according to the data passed via \fBsetEnvironment()\fP. 
.PP
Definition at line 183 of file kprocess.cpp.
.PP
References QMap::begin(), QFile::encodeName(), and QMap::end().
.PP
Referenced by start().
.SS "int KProcess::setupCommunication (\fBCommunication\fP comm)\fC [protected, virtual]\fP"
.PP
This function is called from \fBstart()\fP right before a fork() takes place. 
.PP
According to the \fCcomm\fP parameter this function has to initialize the in, out and err data members of KProcess.
.PP
This function should return 1 if setting the needed communication channels was successful.
.PP
The default implementation is to create UNIX STREAM sockets for the communication, but you could reimplement this function to establish a TCP/IP communication for network communication, for example. 
.PP
Definition at line 873 of file kprocess.cpp.
.PP
References communication, endl(), err, in, and out.
.PP
Referenced by start().
.SS "int KProcess::commSetupDoneP ()\fC [protected, virtual]\fP"
.PP
Called right after a (successful) fork() on the parent side. 
.PP
This function will usually do some communications cleanup, like closing in[0], out[1] and out[1].
.PP
Furthermore, it must also create the QSocketNotifiers innot, outnot and errnot and connect their \fBQt\fP signals to the respective KProcess slots.
.PP
For a more detailed explanation, it is best to have a look at the default implementation in \fBkprocess.cpp\fP. 
.PP
Definition at line 941 of file kprocess.cpp.
.PP
References communication, QObject::connect(), err, errnot, in, innot, NotifyOnExit, out, outnot, OwnGroup, run_mode, QSocketNotifier::setEnabled(), slotChildError(), slotChildOutput(), slotSendData(), and suspend().
.PP
Referenced by start().
.SS "int KProcess::commSetupDoneC ()\fC [protected, virtual]\fP"
.PP
Called right after a (successful) fork(), but before an exec() on the child process' side. 
.PP
It usually duplicates the in[0], out[1] and err[1] file handles to the respective standard I/O handles. 
.PP
Definition at line 986 of file kprocess.cpp.
.PP
References communication, err, in, and out.
.PP
Referenced by start().
.SS "void KProcess::processHasExited (int state)\fC [protected, virtual]\fP"
.PP
Immediately called after a successfully started process in NotifyOnExit mode has exited. 
.PP
This function normally calls \fBcommClose()\fP and emits the \fBprocessExited()\fP signal. 
.PP
\fBParameters:\fP
.RS 4
\fIstate\fP the exit code of the process as returned by waitpid() 
.RE
.PP

.PP
Definition at line 820 of file kprocess.cpp.
.PP
References commClose(), DontCare, processExited(), run_mode, runs, and status.
.PP
Referenced by wait().
.SS "void KProcess::commClose ()\fC [protected, virtual]\fP"
.PP
Cleans up the communication links to the child after it has exited. 
.PP
This function should act upon the values of \fBpid()\fP and runs. See the \fBkprocess.cpp\fP source for details. 
.PD 0

.IP "\(bu" 2
If \fBpid()\fP returns zero, the communication links should be closed only. 
.IP "\(bu" 2
if \fBpid()\fP returns non-zero and runs is false, all data immediately available from the communication links should be processed before closing them. 
.IP "\(bu" 2
if \fBpid()\fP returns non-zero and runs is true, the communication links should be monitored for data until the file handle returned by \fBKProcessController::theKProcessController\fP->notifierFd() becomes ready for reading - when it triggers, runs should be reset to false, and the function should be immediately left without closing anything.
.PP
The previous semantics of this function are forward-compatible, but should be avoided, as they are prone to race conditions and can cause KProcess (and thus the whole program) to lock up under certain circumstances. At the end the function closes the communication links in any case. Additionally 
.PD 0

.IP "\(bu" 2
if runs is true, the communication links are monitored for data until all of them have returned EOF. Note that if any system function is interrupted (errno == EINTR) the polling loop should be aborted. 
.IP "\(bu" 2
if runs is false, all data immediately available from the communication links is processed. 
.PP

.PP
Definition at line 1032 of file kprocess.cpp.
.PP
References closePty(), closeStderr(), closeStdin(), closeStdout(), communication, err, KProcessController::notifierFd(), out, pid_, runs, slotChildError(), and slotChildOutput().
.PP
Referenced by detach(), processHasExited(), and start().
.SS "void KProcess::setBinaryExecutable (const char * filename)\fC [protected]\fP"
.PP
Specify the actual executable that should be started (first argument to execve) Normally the the first argument is the executable but you can override that with this function. 
.PP
Definition at line 250 of file kprocess.cpp.
.SS "int KProcess::childOutput (int fdno)\fC [protected]\fP"
.PP
Called by \fBslotChildOutput()\fP this function copies data arriving from the child process' stdout to the respective buffer and emits the signal \fBreceivedStdout()\fP. 
.PP
Definition at line 835 of file kprocess.cpp.
.PP
References communication, and receivedStdout().
.PP
Referenced by slotChildOutput().
.SS "int KProcess::childError (int fdno)\fC [protected]\fP"
.PP
Called by \fBslotChildError()\fP this function copies data arriving from the child process' stderr to the respective buffer and emits the signal \fBreceivedStderr()\fP. 
.PP
Definition at line 858 of file kprocess.cpp.
.PP
References receivedStderr().
.PP
Referenced by slotChildError().
.SH "Friends And Related Function Documentation"
.PP 
.SS "friend class \fBKProcessController\fP\fC [friend]\fP"
.PP
\fBKProcessController\fP is a friend of KProcess because it has to have access to various data members. 
.PP
Definition at line 864 of file kprocess.h.
.SH "Member Data Documentation"
.PP 
.SS "\fBQValueList\fP<\fBQCString\fP> \fBKProcess::arguments\fP\fC [protected]\fP"
.PP
The list of the process' command line arguments. 
.PP
The first entry in this list is the executable itself. 
.PP
Definition at line 675 of file kprocess.h.
.PP
Referenced by clearArguments(), operator<<(), setExecutable(), and start().
.SS "\fBRunMode\fP \fBKProcess::run_mode\fP\fC [protected]\fP"
.PP
How to run the process (Block, NotifyOnExit, DontCare). 
.PP
You should not modify this data member directly from derived classes. 
.PP
Definition at line 680 of file kprocess.h.
.PP
Referenced by commSetupDoneP(), kill(), processHasExited(), start(), and ~KProcess().
.SS "bool \fBKProcess::runs\fP\fC [protected]\fP"
.PP
true if the process is currently running. 
.PP
You should not modify this data member directly from derived classes. Please use \fBisRunning()\fP for reading the value of this data member since it will probably be made private in later versions of KProcess. 
.PP
Definition at line 687 of file kprocess.h.
.PP
Referenced by commClose(), detach(), isRunning(), kill(), normalExit(), processHasExited(), setExecutable(), setPriority(), signalled(), start(), and wait().
.SS "pid_t \fBKProcess::pid_\fP\fC [protected]\fP"
.PP
The PID of the currently running process. 
.PP
You should not modify this data member in derived classes. Please use \fBpid()\fP instead of directly accessing this member since it will probably be made private in later versions of KProcess. 
.PP
Definition at line 696 of file kprocess.h.
.PP
Referenced by commClose(), detach(), kill(), normalExit(), pid(), setPriority(), signalled(), start(), and wait().
.SS "int \fBKProcess::status\fP\fC [protected]\fP"
.PP
The process' exit status as returned by waitpid(). 
.PP
You should not modify the value of this data member from derived classes. You should rather use \fBexitStatus()\fP than accessing this data member directly since it will probably be made private in further versions of KProcess. 
.PP
Definition at line 705 of file kprocess.h.
.PP
Referenced by coreDumped(), exitSignal(), exitStatus(), normalExit(), processHasExited(), signalled(), start(), and wait().
.SS "bool \fBKProcess::keepPrivs\fP\fC [protected]\fP"
.PP
If false, the child process' effective uid & gid will be reset to the real values. 
.PP
\fBSee also:\fP
.RS 4
\fBsetRunPrivileged()\fP 
.RE
.PP

.PP
Definition at line 713 of file kprocess.h.
.PP
Referenced by runPrivileged(), and setRunPrivileged().
.SS "int \fBKProcess::out\fP[2]\fC [protected]\fP"
.PP
The socket descriptors for stdout. 
.PP
Definition at line 804 of file kprocess.h.
.PP
Referenced by closeStdout(), commClose(), commSetupDoneC(), commSetupDoneP(), KProcess(), and setupCommunication().
.SS "int \fBKProcess::in\fP[2]\fC [protected]\fP"
.PP
The socket descriptors for stdin. 
.PP
Definition at line 808 of file kprocess.h.
.PP
Referenced by closeStdin(), commSetupDoneC(), commSetupDoneP(), KProcess(), setupCommunication(), and slotSendData().
.SS "int \fBKProcess::err\fP[2]\fC [protected]\fP"
.PP
The socket descriptors for stderr. 
.PP
Definition at line 812 of file kprocess.h.
.PP
Referenced by closeStderr(), commClose(), commSetupDoneC(), commSetupDoneP(), KProcess(), and setupCommunication().
.SS "\fBQSocketNotifier\fP* \fBKProcess::innot\fP\fC [protected]\fP"
.PP
The socket notifier for in[1]. 
.PP
Definition at line 817 of file kprocess.h.
.PP
Referenced by closeStdin(), commSetupDoneP(), slotSendData(), and writeStdin().
.SS "\fBQSocketNotifier\fP* \fBKProcess::outnot\fP\fC [protected]\fP"
.PP
The socket notifier for out[0]. 
.PP
Definition at line 821 of file kprocess.h.
.PP
Referenced by closeStdout(), commSetupDoneP(), resume(), and suspend().
.SS "\fBQSocketNotifier\fP* \fBKProcess::errnot\fP\fC [protected]\fP"
.PP
The socket notifier for err[0]. 
.PP
Definition at line 825 of file kprocess.h.
.PP
Referenced by closeStderr(), and commSetupDoneP().
.SS "\fBCommunication\fP \fBKProcess::communication\fP\fC [protected]\fP"
.PP
Lists the communication links that are activated for the child process. 
.PP
Should not be modified from derived classes. 
.PP
Definition at line 831 of file kprocess.h.
.PP
Referenced by childOutput(), closeStderr(), closeStdin(), closeStdout(), commClose(), commSetupDoneC(), commSetupDoneP(), setupCommunication(), and writeStdin().
.SS "const char* \fBKProcess::input_data\fP\fC [protected]\fP"
.PP
The buffer holding the data that has to be sent to the child. 
.PP
Definition at line 850 of file kprocess.h.
.PP
Referenced by slotSendData(), start(), and writeStdin().
.SS "int \fBKProcess::input_sent\fP\fC [protected]\fP"
.PP
The number of bytes already transmitted. 
.PP
Definition at line 854 of file kprocess.h.
.PP
Referenced by slotSendData(), and writeStdin().
.SS "int \fBKProcess::input_total\fP\fC [protected]\fP"
.PP
The total length of input_data. 
.PP
Definition at line 858 of file kprocess.h.
.PP
Referenced by slotSendData(), and writeStdin().

.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
