KDECore
kprocess.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __kprocess_h__
00021 #define __kprocess_h__
00022
00023 #include <sys/types.h>
00024 #include <sys/wait.h>
00025 #include <signal.h>
00026 #include <unistd.h>
00027 #include <qvaluelist.h>
00028 #include <qcstring.h>
00029 #include <qobject.h>
00030 #include "kdelibs_export.h"
00031
00032 class QSocketNotifier;
00033 class KProcessPrivate;
00034 class KPty;
00035
00125 class KDECORE_EXPORT KProcess : public QObject
00126 {
00127 Q_OBJECT
00128
00129 public:
00130
00152 enum Communication {
00153 NoCommunication = 0,
00154 Stdin = 1, Stdout = 2, Stderr = 4,
00155 AllOutput = 6, All = 7,
00156 NoRead = 8,
00157 CTtyOnly = NoRead,
00158 MergedStderr = 16
00159 };
00160
00164 enum RunMode {
00169 DontCare,
00173 NotifyOnExit,
00177 Block,
00182 OwnGroup
00183 };
00184
00189 KProcess( QObject* parent, const char *name = 0 );
00190
00194 KProcess();
00195
00204 virtual ~KProcess();
00205
00217 bool setExecutable(const QString& proc) KDE_DEPRECATED;
00218
00219
00233 KProcess &operator<<(const QString& arg);
00237 KProcess &operator<<(const char * arg);
00243 KProcess &operator<<(const QCString & arg);
00244
00251 KProcess &operator<<(const QStringList& args);
00252
00257 void clearArguments();
00258
00285 virtual bool start(RunMode runmode = NotifyOnExit,
00286 Communication comm = NoCommunication);
00287
00294 virtual bool kill(int signo = SIGTERM);
00295
00300 bool isRunning() const;
00301
00312 pid_t pid() const;
00313
00318 KDE_DEPRECATED pid_t getPid() const { return pid(); }
00319
00323 void suspend();
00324
00328 void resume();
00329
00338 bool wait(int timeout = -1);
00339
00346 bool normalExit() const;
00347
00356 bool signalled() const;
00357
00367 bool coreDumped() const;
00368
00375 int exitStatus() const;
00376
00385 int exitSignal() const;
00386
00417 bool writeStdin(const char *buffer, int buflen);
00418
00425 bool closeStdin();
00426
00434 bool closeStdout();
00435
00443 bool closeStderr();
00444
00453 bool closePty();
00454
00461 void closeAll();
00462
00467 const QValueList<QCString> &args() { return arguments; }
00468
00478 void setRunPrivileged(bool keepPrivileges);
00479
00485 bool runPrivileged() const;
00486
00493 void setEnvironment(const QString &name, const QString &value);
00494
00501 void setWorkingDirectory(const QString &dir);
00502
00519 void setUseShell(bool useShell, const char *shell = 0);
00520
00530 static QString quote(const QString &arg);
00531
00539 void detach();
00540
00541 #ifdef Q_OS_UNIX
00542
00553 void setUsePty(Communication comm, bool addUtmp);
00554
00562 KPty *pty() const;
00563 #endif
00564
00568 enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
00569 PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
00570
00577 bool setPriority(int prio);
00578
00579 signals:
00586 void processExited(KProcess *proc);
00587
00588
00607 void receivedStdout(KProcess *proc, char *buffer, int buflen);
00608
00627 void receivedStdout(int fd, int &len);
00628
00629
00644 void receivedStderr(KProcess *proc, char *buffer, int buflen);
00645
00652 void wroteStdin(KProcess *proc);
00653
00654
00655 protected slots:
00656
00662 void slotChildOutput(int fdno);
00663
00669 void slotChildError(int fdno);
00670
00677 void slotSendData(int dummy);
00678
00679 protected:
00680
00685 void setupEnvironment();
00686
00691 QValueList<QCString> arguments;
00696 RunMode run_mode;
00703 bool runs;
00704
00712 pid_t pid_;
00713
00721 int status;
00722
00723
00729 bool keepPrivs;
00730
00743 virtual int setupCommunication(Communication comm);
00744
00757 virtual int commSetupDoneP();
00758
00764 virtual int commSetupDoneC();
00765
00766
00773 virtual void processHasExited(int state);
00774
00800 virtual void commClose();
00801
00802
00803
00804
00805
00806
00807
00808
00809
00815 void setBinaryExecutable(const char *filename);
00816
00820 int out[2];
00824 int in[2];
00828 int err[2];
00829
00833 QSocketNotifier *innot;
00837 QSocketNotifier *outnot;
00841 QSocketNotifier *errnot;
00842
00847 Communication communication;
00848
00854 int childOutput(int fdno);
00855
00861 int childError(int fdno);
00862
00866 const char *input_data;
00870 int input_sent;
00874 int input_total;
00875
00880 friend class KProcessController;
00881
00882 protected:
00883 virtual void virtual_hook( int id, void* data );
00884 private:
00885 KProcessPrivate *d;
00886 };
00887
00888 class KShellProcessPrivate;
00889
00899 class KDECORE_EXPORT KShellProcess: public KProcess
00900 {
00901 Q_OBJECT
00902
00903 public:
00904
00910 KShellProcess(const char *shellname=0);
00911
00915 ~KShellProcess();
00916
00917 virtual bool start(RunMode runmode = NotifyOnExit,
00918 Communication comm = NoCommunication);
00919
00920 static QString quote(const QString &arg);
00921
00922 private:
00923 QCString shell;
00924
00925 protected:
00926 virtual void virtual_hook( int id, void* data );
00927 private:
00928 KShellProcessPrivate *d;
00929 };
00930
00931
00932
00933 #endif
00934