kalarm/lib

shellprocess.h
Go to the documentation of this file.
1/*
2 * shellprocess.h - execute a process through the shell
3 * Program: kalarm
4 * Copyright © 2004-2006 by David Jarvie <software@astrojar.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef SHELLPROCESS_H
22#define SHELLPROCESS_H
23
26#include <tdeprocess.h>
27
28
50class ShellProcess : public KShellProcess
51{
52 TQ_OBJECT
53
54 public:
64 enum Status {
65 INACTIVE, // start() has not yet been called to run the command
66 RUNNING, // command is currently running
67 SUCCESS, // command appears to have exited successfully
68 UNAUTHORISED, // shell commands are not authorised for this user
69 DIED, // command didn't exit cleanly, i.e. was killed or died
70 NOT_FOUND, // command either not found or not executable
71 START_FAIL // command couldn't be started for other reasons
72 };
76 explicit ShellProcess(const TQString& command);
81 bool start(Communication comm = NoCommunication);
83 Status status() const { return mStatus; }
87 bool normalExit() const { return mStatus == SUCCESS; }
89 const TQString& command() const { return mCommand; }
94 TQString errorMessage() const;
96 void writeStdin(const char* buffer, int bufflen);
98 void stdinExit();
102 static bool authorised();
106 static const TQCString& shellName() { shellPath(); return mShellName; }
110 static const TQCString& shellPath();
111
112 signals:
117
118 private slots:
119 void writtenStdin(TDEProcess*);
120 void slotExited(TDEProcess*);
121
122 private:
123 // Prohibit the following inherited methods
124 ShellProcess& operator<<(const TQString&);
125 ShellProcess& operator<<(const TQCString&);
126 ShellProcess& operator<<(const TQStringList&);
127 ShellProcess& operator<<(const char*);
128
129 static TQCString mShellName; // name of shell to be used
130 static TQCString mShellPath; // path of shell to be used
131 static bool mInitialised; // true once static data has been initialised
132 static bool mAuthorised; // true if shell commands are authorised
133 TQString mCommand; // copy of command to be executed
134 TQValueList<TQCString> mStdinQueue; // queued strings to send to STDIN
135 Status mStatus; // current execution status
136 bool mStdinExit; // exit once STDIN queue has been written
137};
138
139#endif // SHELLPROCESS_H
Enhanced KShellProcess.
Definition: shellprocess.h:51
static bool authorised()
Returns whether the user is authorised to run shell commands.
void shellExited(ShellProcess *)
Signal emitted when the shell process execution completes.
Status
Current status of the shell process.
Definition: shellprocess.h:64
TQString errorMessage() const
Returns the error message corresponding to the command exit status.
static const TQCString & shellPath()
Determines which shell to use.
ShellProcess(const TQString &command)
Constructor.
bool normalExit() const
Returns whether the command was run successfully.
Definition: shellprocess.h:87
void writeStdin(const char *buffer, int bufflen)
Writes a string to the process's STDIN.
void stdinExit()
Tell the process to exit once any outstanding STDIN strings have been written.
bool start(Communication comm=NoCommunication)
Executes the configured command.
Status status() const
Returns the current status of the shell process.
Definition: shellprocess.h:83
static const TQCString & shellName()
Determines which shell to use.
Definition: shellprocess.h:106
const TQString & command() const
Returns the command configured to be run.
Definition: shellprocess.h:89