kprocess.h
/* This file is part of the KDE libraries
Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __kprocess_h__
#define __kprocess_h__
#include <sys/types.h> // for pid_t
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <qvaluelist.h>
#include <qcstring.h>
#include <qobject.h>
#include "kdelibs_export.h"
class QSocketNotifier;
class KProcessPrivate;
class KPty;
class KDECORE_EXPORT KProcess : public QObject
{
Q_OBJECT
public:
enum Communication {
NoCommunication = 0,
Stdin = 1, Stdout = 2, Stderr = 4,
AllOutput = 6, All = 7,
NoRead = 8,
CTtyOnly = NoRead,
MergedStderr = 16
};
enum RunMode {
DontCare,
NotifyOnExit,
Block,
OwnGroup
};
KProcess( QObject* parent, const char *name = 0 );
// KDE4 merge with the above
KProcess();
virtual ~KProcess();
bool setExecutable(const QString& proc) KDE_DEPRECATED;
KProcess &operator<<(const QString& arg);
KProcess &operator<<(const char * arg);
KProcess &operator<<(const QCString & arg);
KProcess &operator<<(const QStringList& args);
void clearArguments();
virtual bool start(RunMode runmode = NotifyOnExit,
Communication comm = NoCommunication);
virtual bool kill(int signo = SIGTERM);
bool isRunning() const;
pid_t pid() const;
KDE_DEPRECATED pid_t getPid() const { return pid(); }
void suspend();
void resume();
bool wait(int timeout = -1);
bool normalExit() const;
bool signalled() const;
bool coreDumped() const;
int exitStatus() const;
int exitSignal() const;
bool writeStdin(const char *buffer, int buflen);
bool closeStdin();
bool closeStdout();
bool closeStderr();
bool closePty();
void closeAll();
const QValueList<QCString> &args() /* const */ { return arguments; }
void setRunPrivileged(bool keepPrivileges);
bool runPrivileged() const;
void setEnvironment(const QString &name, const QString &value);
void setWorkingDirectory(const QString &dir);
void setUseShell(bool useShell, const char *shell = 0);
static QString quote(const QString &arg);
void detach();
#ifdef Q_OS_UNIX
void setUsePty(Communication comm, bool addUtmp);
KPty *pty() const;
#endif
enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
bool setPriority(int prio);
signals:
void processExited(KProcess *proc);
void receivedStdout(KProcess *proc, char *buffer, int buflen);
void receivedStdout(int fd, int &len); // KDE4: change, broken API
void receivedStderr(KProcess *proc, char *buffer, int buflen);
void wroteStdin(KProcess *proc);
protected slots:
void slotChildOutput(int fdno);
void slotChildError(int fdno);
void slotSendData(int dummy); // KDE 4: remove dummy
protected:
void setupEnvironment();
QValueList<QCString> arguments;
RunMode run_mode;
bool runs;
pid_t pid_;
int status;
bool keepPrivs;
virtual int setupCommunication(Communication comm);
virtual int commSetupDoneP();
virtual int commSetupDoneC();
virtual void processHasExited(int state);
virtual void commClose();
/* KDE 4 - commClose will be changed to perform cleanup only in all cases *
* If @p notfd is -1, all data immediately available from the
* communication links should be processed.
* If @p notfd is not -1, the communication links should be monitored
* for data until the file handle @p notfd becomes ready for reading.
*/
// virtual void commDrain(int notfd);
void setBinaryExecutable(const char *filename);
int out[2];
int in[2];
int err[2];
QSocketNotifier *innot;
QSocketNotifier *outnot;
QSocketNotifier *errnot;
Communication communication;
int childOutput(int fdno);
int childError(int fdno);
const char *input_data;
int input_sent;
int input_total;
friend class KProcessController;
protected:
virtual void virtual_hook( int id, void* data );
private:
KProcessPrivate *d;
};
class KShellProcessPrivate;
class KDECORE_EXPORT KShellProcess: public KProcess
{
Q_OBJECT
public:
KShellProcess(const char *shellname=0);
~KShellProcess();
virtual bool start(RunMode runmode = NotifyOnExit,
Communication comm = NoCommunication);
static QString quote(const QString &arg);
private:
QCString shell;
protected:
virtual void virtual_hook( int id, void* data );
private:
KShellProcessPrivate *d;
};
#endif
KProcess::run_mode
RunMode run_mode
How to run the process (Block, NotifyOnExit, DontCare).
Definition: kprocess.h:696
KProcess::innot
QSocketNotifier * innot
The socket notifier for in[1].
Definition: kprocess.h:833
KProcess
Child process invocation, monitoring and control.
Definition: kprocess.h:125
KProcess::NotifyOnExit
The application is notified when the subprocess dies.
Definition: kprocess.h:173
KProcess::errnot
QSocketNotifier * errnot
The socket notifier for err[0].
Definition: kprocess.h:841
KShellProcess
A class derived from KProcess to start child processes through a shell.
Definition: kprocess.h:899
KProcess::outnot
QSocketNotifier * outnot
The socket notifier for out[0].
Definition: kprocess.h:837
KProcess::input_sent
int input_sent
The number of bytes already transmitted.
Definition: kprocess.h:870
KProcess::start
virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication)
Starts the process.
Definition: kprocess.cpp:298
KProcess::getPid
KDE_DEPRECATED pid_t getPid() const
Definition: kprocess.h:318
KProcess::arguments
QValueList< QCString > arguments
The list of the process' command line arguments.
Definition: kprocess.h:691
KProcess::status
int status
The process' exit status as returned by waitpid().
Definition: kprocess.h:721
KProcess::runs
bool runs
true if the process is currently running.
Definition: kprocess.h:703
KProcess::args
const QValueList< QCString > & args()
Lets you see what your arguments are for debugging.
Definition: kprocess.h:467
KProcess::communication
Communication communication
Lists the communication links that are activated for the child process.
Definition: kprocess.h:847
KProcessController
Used internally by KProcess.
Definition: kprocctrl.h:39
KProcess::DontCare
The application does not receive notifications from the subprocess when it is finished or aborted...
Definition: kprocess.h:169
KProcess::quote
static QString quote(const QString &arg)
This function can be used to quote an argument string such that the shell processes it properly...
Definition: kprocess.cpp:809
KProcess::input_total
int input_total
The total length of input_data.
Definition: kprocess.h:874
KProcess::keepPrivs
bool keepPrivs
If false, the child process' effective uid & gid will be reset to the real values.
Definition: kprocess.h:729
KProcess::Block
The application is suspended until the started process is finished.
Definition: kprocess.h:177
KProcess::pid_
pid_t pid_
The PID of the currently running process.
Definition: kprocess.h:712
KProcess::Communication
Communication
Modes in which the communication channel can be opened.
Definition: kprocess.h:152
KPty
Provides a high level representation of a pseudo tty pair, including utmp support.
Definition: kpty.h:40
KProcess::RunMode
RunMode
Run-modes for a child process.
Definition: kprocess.h:164
KProcess::input_data
const char * input_data
The buffer holding the data that has to be sent to the child.
Definition: kprocess.h:866

KDE Home | KDE Accessibility Home | Description of Access Keys