.TH "KProcess" 3 "28 Jan 2004" "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
.RI "\fIModes in which the communication channel can be opened. \fP"
.ti -1c
.RI "enum \fBRunMode\fP { \fBDontCare\fP, \fBNotifyOnExit\fP, \fBBlock\fP }"
.br
.RI "\fIRun-modes for a child process. \fP"
.in -1c
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBprocessExited\fP (\fBKProcess\fP *proc)"
.br
.RI "\fIEmitted after the process has terminated when the process was run in the \fCNotifyOnExit\fP (==default option to \fBstart\fP()) or the \fBBlock\fP mode. \fP"
.ti -1c
.RI "void \fBreceivedStdout\fP (\fBKProcess\fP *proc, char *buffer, int buflen)"
.br
.RI "\fIEmitted, when output from the child process has been received on stdout. \fP"
.ti -1c
.RI "void \fBreceivedStdout\fP (int fd, int &len)"
.br
.RI "\fIEmitted when output from the child process has been received on stdout. \fP"
.ti -1c
.RI "void \fBreceivedStderr\fP (\fBKProcess\fP *proc, char *buffer, int buflen)"
.br
.RI "\fIEmitted, when output from the child process has been received on stderr. \fP"
.ti -1c
.RI "void \fBwroteStdin\fP (\fBKProcess\fP *proc)"
.br
.RI "\fIEmitted after all the data that has been specified by a prior call to \fBwriteStdin\fP() has actually been written to the child process. \fP"
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKProcess\fP ()"
.br
.RI "\fIConstructor. \fP"
.ti -1c
.RI "virtual \fB~KProcess\fP ()"
.br
.RI "\fIDestructor:. \fP"
.ti -1c
.RI "bool \fBsetExecutable\fP (const  \fBQString\fP &proc)"
.br
.RI "\fI\fBThis class or method is obsolete, it is provided for compatibility only.\fP \fP"
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const  \fBQString\fP &arg)"
.br
.RI "\fISets the executable and the command line argument list for this process. \fP"
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const  char *arg)"
.br
.RI "\fISimilar to previous method, takes a char *, supposed to be in locale 8 bit already. \fP"
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const  \fBQCString\fP &arg)"
.br
.RI "\fISimilar to previous method, takes a \fBQCString\fP, supposed to be in locale 8 bit already. \fP"
.ti -1c
.RI "\fBKProcess\fP & \fBoperator<<\fP (const  \fBQStringList\fP &args)"
.br
.RI "\fISets the executable and the command line argument list for this process, in a single method call, or add a list of arguments. \fP"
.ti -1c
.RI "void \fBclearArguments\fP ()"
.br
.RI "\fIClear a command line argument list that has been set by using the 'operator<<'. \fP"
.ti -1c
.RI "virtual bool \fBstart\fP (\fBRunMode\fP runmode=NotifyOnExit, \fBCommunication\fP comm=NoCommunication)"
.br
.RI "\fIStarts the process. \fP"
.ti -1c
.RI "virtual bool \fBkill\fP (int signo=SIGTERM)"
.br
.RI "\fIStop the process (by sending it a signal). \fP"
.ti -1c
.RI "bool \fBisRunning\fP () const "
.br
.RI "\fIChecks whether the process is running. \fP"
.ti -1c
.RI "pid_t \fBpid\fP () const "
.br
.RI "\fIReturns the process id of the process. \fP"
.ti -1c
.RI "pid_t \fBgetPid\fP () const "
.br
.RI "\fIUse \fBpid()\fP. \fP"
.ti -1c
.RI "void \fBsuspend\fP ()"
.br
.RI "\fISuspend processing of data from stdout of the child process. \fP"
.ti -1c
.RI "void \fBresume\fP ()"
.br
.RI "\fIResume processing of data from stdout of the child process. \fP"
.ti -1c
.RI "bool \fBnormalExit\fP () const "
.br
.ti -1c
.RI "int \fBexitStatus\fP () const "
.br
.RI "\fIReturns the exit status of the process. \fP"
.ti -1c
.RI "bool \fBwriteStdin\fP (const  char *buffer, int buflen)"
.br
.RI "\fITransmit data to the child process's stdin. \fP"
.ti -1c
.RI "bool \fBcloseStdin\fP ()"
.br
.RI "\fIThis causes the stdin file descriptor of the child process to be closed indicating an 'EOF' to the child. \fP"
.ti -1c
.RI "bool \fBcloseStdout\fP ()"
.br
.RI "\fIThis causes the stdout file descriptor of the child process to be closed. \fP"
.ti -1c
.RI "bool \fBcloseStderr\fP ()"
.br
.RI "\fIThis causes the stderr file descriptor of the child process to be closed. \fP"
.ti -1c
.RI "const  \fBQValueList\fP< \fBQCString\fP > & \fBargs\fP ()"
.br
.RI "\fILets you see what your arguments are for debugging. \fP"
.ti -1c
.RI "void \fBsetRunPrivileged\fP (bool keepPrivileges)"
.br
.RI "\fIControls whether the started process should drop any setuid/segid privileges or whether it should keep them. \fP"
.ti -1c
.RI "bool \fBrunPrivileged\fP () const "
.br
.RI "\fIReturns whether the started process will drop any setuid/segid privileges or whether it will keep them. \fP"
.ti -1c
.RI "void \fBsetEnvironment\fP (const  \fBQString\fP &\fBname\fP, const  \fBQString\fP &value)"
.br
.RI "\fIModifies the environment of the process to be started. \fP"
.ti -1c
.RI "void \fBsetWorkingDirectory\fP (const  \fBQString\fP &dir)"
.br
.RI "\fIChanges the current working directory (CWD) of the process to be started. \fP"
.ti -1c
.RI "void \fBsetUseShell\fP (bool useShell, const  char *shell=0)"
.br
.RI "\fISpecify whether to start the command via a shell or directly. \fP"
.ti -1c
.RI "void \fBdetach\fP ()"
.br
.RI "\fIDetaches KProcess from child process. \fP"
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "\fBQString\fP \fBquote\fP (const  \fBQString\fP &arg)"
.br
.RI "\fIThis function can be used to quote an argument string such that the shell processes it properly. \fP"
.in -1c
.SS "Protected Slots"

.in +1c
.ti -1c
.RI "void \fBslotChildOutput\fP (int fdno)"
.br
.RI "\fIThis slot gets activated when data from the child's stdout arrives. \fP"
.ti -1c
.RI "void \fBslotChildError\fP (int fdno)"
.br
.RI "\fIThis slot gets activated when data from the child's stderr arrives. \fP"
.ti -1c
.RI "void \fBslotSendData\fP (int dummy)"
.br
.RI "\fICalled when another bulk of data can be sent to the child's stdin. \fP"
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "void \fBsetupEnvironment\fP ()"
.br
.RI "\fISets up the environment according to the data passed via setEnvironment(...). \fP"
.ti -1c
.RI "virtual int \fBsetupCommunication\fP (\fBCommunication\fP comm)"
.br
.RI "\fIThis function is called from 'KProcess::start' right before a 'fork' takes place. \fP"
.ti -1c
.RI "virtual int \fBcommSetupDoneP\fP ()"
.br
.RI "\fICalled right after a (successful) fork on the parent side. \fP"
.ti -1c
.RI "virtual int \fBcommSetupDoneC\fP ()"
.br
.RI "\fICalled right after a (successful) fork, but before an 'exec' on the child process' side. \fP"
.ti -1c
.RI "virtual void \fBprocessHasExited\fP (int state)"
.br
.RI "\fIImmediately called after a process has exited. \fP"
.ti -1c
.RI "virtual void \fBcommClose\fP ()"
.br
.RI "\fIShould clean up the communication links to the child after it has exited. \fP"
.ti -1c
.RI "int \fBchildOutput\fP (int fdno)"
.br
.RI "\fICalled by 'slotChildOutput' this function copies data arriving from the child process's stdout to the respective buffer and emits the signal '@ref receivedStderr'. \fP"
.ti -1c
.RI "int \fBchildError\fP (int fdno)"
.br
.RI "\fICalled by 'slotChildOutput' this function copies data arriving from the child process's stdout to the respective buffer and emits the signal '@ref receivedStderr'. \fP"
.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
.RI "\fIThe list of the process' command line arguments. \fP"
.ti -1c
.RI "\fBRunMode\fP \fBrun_mode\fP"
.br
.RI "\fIHow to run the process (Block, NotifyOnExit, DontCare). \fP"
.ti -1c
.RI "bool \fBruns\fP"
.br
.RI "\fItrue if the process is currently running. \fP"
.ti -1c
.RI "pid_t \fBpid_\fP"
.br
.RI "\fIThe PID of the currently running process (see 'getPid()'). \fP"
.ti -1c
.RI "int \fBstatus\fP"
.br
.RI "\fIThe process' exit status as returned by 'waitpid'. \fP"
.ti -1c
.RI "bool \fBkeepPrivs\fP"
.br
.RI "\fISee \fBsetRunPrivileged()\fP. \fP"
.ti -1c
.RI "int \fBout\fP [2]"
.br
.RI "\fIthe socket descriptors for stdin/stdout/stderr. \fP"
.ti -1c
.RI "int \fBin\fP [2]"
.br
.ti -1c
.RI "int \fBerr\fP [2]"
.br
.ti -1c
.RI "\fBQSocketNotifier\fP * \fBinnot\fP"
.br
.RI "\fIThe socket notifiers for the above socket descriptors. \fP"
.ti -1c
.RI "\fBQSocketNotifier\fP * \fBoutnot\fP"
.br
.ti -1c
.RI "\fBQSocketNotifier\fP * \fBerrnot\fP"
.br
.ti -1c
.RI "\fBCommunication\fP \fBcommunication\fP"
.br
.RI "\fILists the communication links that are activated for the child process. \fP"
.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
.RI "\fI\fBKProcessController\fP is a friend of KProcess because it has to have access to various data members. \fP"
.in -1c
.SH "Detailed Description"
.PP 
Child process invocation, monitoring and control. 

\fB General usage and features\fP
.PP
\fBThis class allows a \fBKDE\fP application to start child processes without having to worry about UN*X signal handling issues and zombie process reaping.\fP
.PP
\fB
.PP
\fBSee also:\fP
.RS 4
\fBKProcIO\fP
.RE
.PP
Basically, this class distinguishes three different ways of running child processes:\fP
.PP
\fB
.IP "\(bu" 2
\fBKProcess::DontCare\fP -- The child process is invoked and both the child process and the parent process continue concurrently.
.PP
Starting a DontCare child process means that the application is not interested in any notification to determine whether the child process has already exited or not.\fP
.PP
\fB
.IP "\(bu" 2
\fBKProcess::NotifyOnExit\fP -- 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().\fP
.PP
\fBSince this signal is \fInot\fP emitted from within a UN*X signal handler, arbitrary function calls can be made.\fP
.PP
\fBBe aware: When the KProcess objects gets destructed, the child process will be killed if it is still running! This means in particular, that you cannot use a KProcess on the stack with \fBKProcess::NotifyOnExit\fP.\fP
.PP
\fB
.IP "\(bu" 2
\fBKProcess::Block\fP -- The child process starts and the parent process is suspended until the child process exits. (\fIReally\fP not recommended for programs with a GUI.)
.PP
KProcess also provides several functions for determining the exit status and the pid of the child process it represents.\fP
.PP
\fBFurthermore it is possible to supply command-line arguments to the process in a clean fashion (no null -- terminated stringlists and such...)\fP
.PP
\fBA small usage example: 
.PP
.nf

 *KProcess *proc = new KProcess;
.PP
\fP
.PP
\fB
.PP
.nf
 **proc << 'my_executable';
 **proc << 'These' << 'are' << 'the' << 'command' << 'line' << 'args';
 *QApplication::connect(proc, SIGNAL(\fBprocessExited(KProcess *)\fP),
                      pointer_to_my_object, SLOT(my_objects_slot(KProcess *)));
 *proc->\fBstart()\fP;
 *
.PP
\fP
.PP
\fBThis will start 'my_executable' with the commandline arguments 'These'...\fP
.PP
\fBWhen the child process exits, the respective \fBQt\fP signal will be emitted.\fP
.PP
\fB\fP
.PP
\fB\fB Communication with the child process\fP\fP
.PP
\fB\fBKProcess supports communication with the child process through stdin/stdout/stderr.\fP\fP
.PP
\fB\fBThe 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):\fP\fP
.PP
\fB\fB
.IP "\(bu" 2
bool \fBwriteStdin\fP(char *buffer, int buflen); 
.IP "\(bu" 2
-- Transmit data to the child process's stdin.
.PP
.IP "\(bu" 2
bool \fBcloseStdin\fP(); 
.IP "\(bu" 2
-- Closes the child process's stdin (which causes it to see an feof(stdin)). Returns false if you try to close stdin for a process that has been started without a communication channel to stdin.
.PP
.IP "\(bu" 2
bool \fBcloseStdout\fP(); 
.IP "\(bu" 2
-- Closes the child process's stdout. Returns false if you try to close stdout for a process that has been started without a communication channel to stdout.
.PP
.IP "\(bu" 2
bool \fBcloseStderr\fP(); 
.IP "\(bu" 2
-- Closes the child process's stderr. Returns false if you try to close stderr for a process that has been started without a communication channel to stderr.
.PP
\fP\fP
.PP
\fB\fB\fB QT signals:\fP\fP\fP
.PP
\fB\fB\fB
.IP "\(bu" 2
void \fBreceivedStdout\fP(KProcess *proc, char *buffer, int buflen); 
.IP "\(bu" 2
void \fBreceivedStderr\fP(KProcess *proc, char *buffer, int buflen); 
.IP "\(bu" 2
-- Indicates that new data has arrived from either the child process's stdout or stderr.
.PP
.IP "\(bu" 2
void \fBwroteStdin\fP(KProcess *proc); 
.IP "\(bu" 2
-- Indicates that all data that has been sent to the child process by a prior call to \fBwriteStdin\fP() has actually been transmitted to the client .
.PP
\fBAuthor:\fP
.RS 4
Christian Czezakte e9025461@student.tuwien.ac.at 
.RE
.PP
\fP\fP\fP
.PP
Definition at line 146 of file kprocess.h.
.SH "Member Enumeration Documentation"
.PP 
.SS "enum \fBKProcess::Communication\fP"
.PP
Modes in which the communication channel can be opened. 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 \fBchildOutput\fP(int fd) is emitted. Definition at line 164 of file kprocess.h.
.PP
Referenced by closeStdin(), closeStdout(), commClose(), and setupCommunication().
.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. 
.PP
Definition at line 171 of file kprocess.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KProcess::KProcess ()"
.PP
Constructor. Definition at line 89 of file kprocess.cpp.
.PP
References KProcessController::addKProcess(), KProcessController, out, and KProcessController::theKProcessController.
.SS "KProcess::~\fBKProcess\fP ()\fC [virtual]\fP"
.PP
Destructor:. 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. Definition at line 159 of file kprocess.cpp.
.PP
References closeStderr(), closeStdin(), closeStdout(), DontCare, kill(), KProcessController::removeKProcess(), run_mode, runs, and KProcessController::theKProcessController.
.SH "Member Function Documentation"
.PP 
.SS "bool KProcess::setExecutable (const \fBQString\fP & proc)"
.PP
\fBThis class or method is obsolete, it is provided for compatibility only.\fP The use of this function is now deprecated. -- Please use the 'operator<<' instead of 'setExecutable'.
.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
Definition at line 195 of file kprocess.cpp.
.PP
References arguments, QValueList< QCString >::begin(), QFile::encodeName(), QValueList< QCString >::isEmpty(), QString::isEmpty(), QValueList< QCString >::prepend(), QValueList< QCString >::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. For example, doing an 'ls -l /usr/local/bin' can be achieved by: 
.PP
.nf

  KProcess p;
  ...
  p << 'ls' << '-l' << '/usr/local/bin'
  
.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
Definition at line 227 of file kprocess.cpp.
.PP
References QValueList< QCString >::append(), arguments, and QFile::encodeName().
.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. Definition at line 221 of file kprocess.cpp.
.PP
References QValueList< QCString >::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. \fBParameters:\fP
.RS 4
\fIarg\fP the argument to add 
.RE
.PP
\fBReturns:\fP
.RS 4
a reference to this KProcess 
.RE
.PP
Definition at line 216 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. \fBParameters:\fP
.RS 4
\fIarg\fP the arguments to add 
.RE
.PP
\fBReturns:\fP
.RS 4
a reference to this KProcess 
.RE
.PP
Definition at line 208 of file kprocess.cpp.
.PP
References QValueList< QCString >::append(), arguments, and QFile::encodeName().
.SS "void KProcess::clearArguments ()"
.PP
Clear a command line argument list that has been set by using the 'operator<<'. Definition at line 233 of file kprocess.cpp.
.PP
References arguments, and QValueList< QCString >::clear().
.PP
Referenced by KProcIO::resetAll().
.SS "bool KProcess::start (\fBRunMode\fP runmode = NotifyOnExit, \fBCommunication\fP comm = NoCommunication)\fC [virtual]\fP"
.PP
Starts the process. For a detailed description of the various run modes and communication semantics, have a look at the general description of the KProcess class.
.PP
The following problems could cause this function to return false:
.PP
.IP "\(bu" 2
The process is already running. 
.IP "\(bu" 2
The command line argument list is empty. 
.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
Reimplemented in \fBKShellProcess\fP.
.PP
Definition at line 238 of file kprocess.cpp.
.PP
References arguments, Block, KStdAction::close(), commClose(), commSetupDoneC(), commSetupDoneP(), QValueList< QCString >::count(), DontCare, QApplication::flushX(), pid_, processExited(), run_mode, runPrivileged(), runs, setupCommunication(), setupEnvironment(), status, and KProcessController::theKProcessController.
.PP
Referenced by KProcIO::start(), and KShellProcess::start().
.SS "bool KProcess::kill (int signo = SIGTERM)\fC [virtual]\fP"
.PP
Stop the process (by sending it a signal). \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
Definition at line 406 of file kprocess.cpp.
.PP
References pid_.
.PP
Referenced by KProcIO::resetAll(), and ~KProcess().
.SS "bool KProcess::isRunning () const"
.PP
Checks whether the process is running. \fBReturns:\fP
.RS 4
true if the process is (still) considered to be running 
.RE
.PP
Definition at line 418 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. 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
Definition at line 425 of file kprocess.cpp.
.PP
References pid_.
.PP
Referenced by getPid().
.SS "pid_t KProcess::getPid () const\fC [inline]\fP"
.PP
Use \fBpid()\fP. \fBThis class or method is obsolete, it is provided for compatibility only.\fP Definition at line 312 of file kprocess.h.
.PP
References pid().
.SS "void KProcess::suspend ()"
.PP
Suspend processing of data from stdout of the child process. Definition at line 471 of file kprocess.cpp.
.PP
References communication, and QSocketNotifier::setEnabled().
.PP
Referenced by commSetupDoneP().
.SS "void KProcess::resume ()"
.PP
Resume processing of data from stdout of the child process. Definition at line 477 of file kprocess.cpp.
.PP
References communication, and QSocketNotifier::setEnabled().
.SS "bool KProcess::normalExit () const"
.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
Note that you should check \fBKProcess::exitStatus\fP() to determine whether the process completed its task successful or not. Definition at line 432 of file kprocess.cpp.
.PP
References pid_, runs, and status.
.SS "int KProcess::exitStatus () const"
.PP
Returns the exit status of the process. Please use \fBKProcess::normalExit\fP() to check whether the process has exited cleanly (i.e., \fBKProcess::normalExit\fP() returns true) before calling this function because if the process did not exit normally, it does not have a valid exit status. 
.PP
\fBReturns:\fP
.RS 4
the exit status of the process 
.RE
.PP
Definition at line 440 of file kprocess.cpp.
.PP
References status.
.SS "bool KProcess::writeStdin (const char * buffer, int buflen)"
.PP
Transmit data to the child process's stdin. \fBKProcess::writeStdin\fP may return false in the following cases:
.PP
.IP "\(bu" 2
The process is not currently running.
.PP
.IP "\(bu" 2
Communication to stdin has not been requested in the \fBstart\fP() call.
.PP
.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.
.PP
If all the data has been sent to the client, the signal \fBwroteStdin\fP() will be emitted.
.PP
Please note that you must not free 'buffer' or call \fBwriteStdin\fP() again until either a \fBwroteStdin\fP() signal indicates that the data has been sent or a \fBprocessHasExited\fP() signal shows that the child process is no longer alive... 
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the buffer to write. Do not free or modify it until you got a \fBwroteStdin\fP() or \fBprocessHasExited\fP() signal 
.RE
.PP
\fBReturns:\fP
.RS 4
false if an error has occurred 
.RE
.PP
Definition at line 448 of file kprocess.cpp.
.PP
References communication, innot, runs, QSocketNotifier::setEnabled(), and slotSendData().
.PP
Referenced by KProcIO::writeStdin().
.SS "bool KProcess::closeStdin ()"
.PP
This causes the stdin file descriptor of the child process to be closed indicating an 'EOF' to the child. \fBReturns:\fP
.RS 4
false if no communication to the process's stdin had been specified in the call to \fBstart\fP(). 
.RE
.PP
Definition at line 483 of file kprocess.cpp.
.PP
References KStdAction::close(), Communication, communication, and innot.
.PP
Referenced by KProcIO::closeWhenDone(), detach(), and ~KProcess().
.SS "bool KProcess::closeStdout ()"
.PP
This causes the stdout file descriptor of the child process to be closed. \fBReturns:\fP
.RS 4
false if no communication to the process's stdout had been specified in the call to \fBstart\fP(). 
.RE
.PP
Definition at line 498 of file kprocess.cpp.
.PP
References KStdAction::close(), Communication, communication, and out.
.PP
Referenced by detach(), slotChildOutput(), and ~KProcess().
.SS "bool KProcess::closeStderr ()"
.PP
This causes the stderr file descriptor of the child process to be closed. \fBReturns:\fP
.RS 4
false if no communication to the process's stderr had been specified in the call to \fBstart\fP(). 
.RE
.PP
Definition at line 513 of file kprocess.cpp.
.PP
References KStdAction::close(), and communication.
.PP
Referenced by detach(), slotChildError(), and ~KProcess().
.SS "const \fBQValueList\fP<\fBQCString\fP>& KProcess::args ()\fC [inline]\fP"
.PP
Lets you see what your arguments are for debugging. \fBReturns:\fP
.RS 4
the list of arguments 
.RE
.PP
Definition at line 406 of file kprocess.h.
.PP
References arguments.
.SS "void KProcess::setRunPrivileged (bool keepPrivileges)"
.PP
Controls whether the started process should drop any setuid/segid privileges or whether it should keep them. The default is false : drop privileges 
.PP
\fBParameters:\fP
.RS 4
\fItrue\fP to keep the privileges 
.RE
.PP
Definition at line 147 of file kprocess.cpp.
.PP
References keepPrivs.
.SS "bool KProcess::runPrivileged () const"
.PP
Returns whether the started process will drop any setuid/segid privileges or whether it will keep them. \fBReturns:\fP
.RS 4
true if the process runs privileged 
.RE
.PP
Definition at line 153 of file kprocess.cpp.
.PP
References keepPrivs.
.PP
Referenced by start().
.SS "void KProcess::setEnvironment (const \fBQString\fP & name, const \fBQString\fP & value)"
.PP
Modifies the environment of the process to be started. 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
Definition at line 117 of file kprocess.cpp.
.PP
References KStdAction::name().
.SS "void KProcess::setWorkingDirectory (const \fBQString\fP & dir)"
.PP
Changes the current working directory (CWD) of the process to be started. This function must be called before starting the process. 
.PP
\fBParameters:\fP
.RS 4
\fIdir\fP the new directory 
.RE
.PP
Definition at line 125 of file kprocess.cpp.
.SS "void KProcess::setUseShell (bool useShell, const char * shell = 0)"
.PP
Specify whether to start the command via a shell or directly. 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, the standard shell is used. \fCquote\fP A flag indicating whether to quote the arguments.
.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 the standard shell 
.RE
.PP
\fBSince:\fP
.RS 4
3.1 
.RE
.PP
Definition at line 844 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. 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 quite 
.RE
.PP
\fBReturns:\fP
.RS 4
the quoted argument 
.RE
.PP
\fBSince:\fP
.RS 4
3.1 
.RE
.PP
Reimplemented in \fBKShellProcess\fP.
.PP
Definition at line 854 of file kprocess.cpp.
.PP
References QString::append(), QString::fromLatin1(), QString::prepend(), and QString::replace().
.PP
Referenced by KShellProcess::quote().
.SS "void KProcess::detach ()"
.PP
Detaches KProcess from child process. 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. Definition at line 182 of file kprocess.cpp.
.PP
References closeStderr(), closeStdin(), closeStdout(), pid_, KProcessController::removeKProcess(), runs, and KProcessController::theKProcessController.
.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 \fBBlock\fP mode. \fBParameters:\fP
.RS 4
\fIproc\fP a pointer to the process that has exited 
.RE
.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. To actually get these signals, the respective communication link (stdout/stderr) 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 this slot. Example: \fBQString\fP myBuf = QString::fromLatin1(buffer, buflen); Referenced by childOutput(), KProcIO::resetAll(), and KProcIO::start().
.SS "void KProcess::receivedStdout (int fd, int & len)\fC [signal]\fP"
.PP
Emitted when output from the child process has been received on stdout. To actually get these signals, the respective communications link (stdout/stderr) has to be turned on in \fBstart\fP() and the \fCNoRead\fP flag should 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's 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 fd 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. To actually get these signals, the respective communication link (stdout/stderr) 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 this 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
Referenced by childError(), KProcIO::resetAll(), and KProcIO::start().
.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. \fBParameters:\fP
.RS 4
\fIproc\fP a pointer to the process 
.RE
.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. It usually calls 'childOutput' 
.PP
\fBParameters:\fP
.RS 4
\fIthe\fP file descriptor for the output 
.RE
.PP
Definition at line 535 of file kprocess.cpp.
.PP
References childOutput(), and closeStdout().
.PP
Referenced by commSetupDoneP().
.SS "void KProcess::slotChildError (int fdno)\fC [protected, slot]\fP"
.PP
This slot gets activated when data from the child's stderr arrives. It usually calls 'childError' 
.PP
\fBParameters:\fP
.RS 4
\fIthe\fP file descriptor for the output 
.RE
.PP
Definition at line 542 of file kprocess.cpp.
.PP
References childError(), and closeStderr().
.PP
Referenced by 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. 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
Definition at line 549 of file kprocess.cpp.
.PP
References innot, 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 setEnvironment(...). Definition at line 133 of file kprocess.cpp.
.PP
References QFile::encodeName().
.PP
Referenced by start().
.SS "int KProcess::setupCommunication (\fBCommunication\fP comm)\fC [protected, virtual]\fP"
.PP
This function is called from 'KProcess::start' right before a 'fork' takes place. According to the 'comm' parameter this function has to initialize the 'in', 'out' and 'err' data member of KProcess.
.PP
This function should return 0 if setting the needed communication channels was successful.
.PP
The default implementation is to create UNIX STREAM sockets for the communication, but you could overload this function and establish a TCP/IP communication for network communication, for example. Definition at line 625 of file kprocess.cpp.
.PP
References KStdAction::close(), Communication, communication, 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. This function will usually do some communications cleanup, like closing the reading end of the 'stdin' communication channel.
.PP
Furthermore, it must also create the QSocketNotifiers 'innot', 'outnot' and 'errnot' and connect their \fBQt\fP slots to the respective KProcess member functions.
.PP
For a more detailed explanation, it is best to have a look at the default implementation of 'setupCommunication' in \fBkprocess.cpp\fP. Definition at line 664 of file kprocess.cpp.
.PP
References Block, KStdAction::close(), communication, QObject::connect(), innot, out, 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. It usually just closes the unused communication ends of 'in', 'out' and 'err' (like the writing end of the 'in' communication channel. Definition at line 712 of file kprocess.cpp.
.PP
References KStdAction::close(), communication, KStdAction::open(), and out.
.PP
Referenced by start().
.SS "void KProcess::processHasExited (int state)\fC [protected, virtual]\fP"
.PP
Immediately called after a process has exited. This function normally calls commClose to close all open communication channels to this process and emits the 'processExited' signal (if the process was not running in the 'DontCare' mode). Definition at line 567 of file kprocess.cpp.
.PP
References commClose(), DontCare, processExited(), run_mode, runs, and status.
.SS "void KProcess::commClose ()\fC [protected, virtual]\fP"
.PP
Should clean up the communication links to the child after it has exited. Should be called from 'processHasExited'. Definition at line 755 of file kprocess.cpp.
.PP
References childError(), childOutput(), KStdAction::close(), Communication, communication, innot, out, and runs.
.PP
Referenced by processHasExited(), and start().
.SS "int KProcess::childOutput (int fdno)\fC [protected]\fP"
.PP
Called by 'slotChildOutput' this function copies data arriving from the child process's stdout to the respective buffer and emits the signal '@ref receivedStderr'. Definition at line 586 of file kprocess.cpp.
.PP
References communication, and receivedStdout().
.PP
Referenced by commClose(), and slotChildOutput().
.SS "int KProcess::childError (int fdno)\fC [protected]\fP"
.PP
Called by 'slotChildOutput' this function copies data arriving from the child process's stdout to the respective buffer and emits the signal '@ref receivedStderr'. Definition at line 611 of file kprocess.cpp.
.PP
References receivedStderr().
.PP
Referenced by commClose(), and 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. Definition at line 741 of file kprocess.h.
.PP
Referenced by KProcess().
.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. The first entry in this list is the executable itself. Definition at line 593 of file kprocess.h.
.PP
Referenced by args(), clearArguments(), operator<<(), setExecutable(), and start().
.SS "\fBRunMode\fP \fBKProcess::run_mode\fP\fC [protected]\fP"
.PP
How to run the process (Block, NotifyOnExit, DontCare). You should not modify this data member directly from derived classes. Definition at line 598 of file kprocess.h.
.PP
Referenced by commSetupDoneP(), processHasExited(), start(), and ~KProcess().
.SS "bool \fBKProcess::runs\fP\fC [protected]\fP"
.PP
true if the process is currently running. You should not modify this data member directly from derived classes. For reading the value of this data member, please use 'isRunning()' since 'runs' will probably be made private in later versions of KProcess. Definition at line 606 of file kprocess.h.
.PP
Referenced by commClose(), detach(), isRunning(), normalExit(), processHasExited(), setExecutable(), start(), writeStdin(), and ~KProcess().
.SS "pid_t \fBKProcess::pid_\fP\fC [protected]\fP"
.PP
The PID of the currently running process (see 'getPid()'). You should not modify this data member in derived classes. Please use 'getPid()' instead of directly accessing this member function since it will probably be made private in later versions of KProcess. Definition at line 615 of file kprocess.h.
.PP
Referenced by detach(), kill(), normalExit(), pid(), and start().
.SS "int \fBKProcess::status\fP\fC [protected]\fP"
.PP
The process' exit status as returned by 'waitpid'. 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. Definition at line 624 of file kprocess.h.
.PP
Referenced by exitStatus(), normalExit(), processHasExited(), and start().
.SS "bool \fBKProcess::keepPrivs\fP\fC [protected]\fP"
.PP
See \fBsetRunPrivileged()\fP. Definition at line 630 of file kprocess.h.
.PP
Referenced by runPrivileged(), and setRunPrivileged().
.SS "int \fBKProcess::out\fP[2]\fC [protected]\fP"
.PP
the socket descriptors for stdin/stdout/stderr. Definition at line 700 of file kprocess.h.
.PP
Referenced by closeStdout(), commClose(), commSetupDoneC(), commSetupDoneP(), KProcess(), and setupCommunication().
.SS "\fBQSocketNotifier\fP* \fBKProcess::innot\fP\fC [protected]\fP"
.PP
The socket notifiers for the above socket descriptors. Definition at line 707 of file kprocess.h.
.PP
Referenced by closeStdin(), commClose(), commSetupDoneP(), slotSendData(), and writeStdin().
.SS "\fBCommunication\fP \fBKProcess::communication\fP\fC [protected]\fP"
.PP
Lists the communication links that are activated for the child process. Should not be modified from derived classes. Definition at line 715 of file kprocess.h.
.PP
Referenced by childOutput(), closeStderr(), closeStdin(), closeStdout(), commClose(), commSetupDoneC(), commSetupDoneP(), resume(), setupCommunication(), suspend(), and writeStdin().

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