0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtCore module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#ifndef QPROCESS_H
|
|
43 |
#define QPROCESS_H
|
|
44 |
|
|
45 |
#include <QtCore/qiodevice.h>
|
|
46 |
#include <QtCore/qstringlist.h>
|
|
47 |
#include <QtCore/qshareddata.h>
|
|
48 |
|
|
49 |
QT_BEGIN_HEADER
|
|
50 |
|
|
51 |
QT_BEGIN_NAMESPACE
|
|
52 |
|
|
53 |
QT_MODULE(Core)
|
|
54 |
|
|
55 |
#ifndef QT_NO_PROCESS
|
|
56 |
|
|
57 |
#if (!defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)) || defined(qdoc)
|
|
58 |
typedef qint64 Q_PID;
|
|
59 |
#else
|
|
60 |
QT_END_NAMESPACE
|
|
61 |
typedef struct _PROCESS_INFORMATION *Q_PID;
|
|
62 |
QT_BEGIN_NAMESPACE
|
|
63 |
#endif
|
|
64 |
|
|
65 |
class QProcessPrivate;
|
|
66 |
class QProcessEnvironmentPrivate;
|
|
67 |
|
|
68 |
class Q_CORE_EXPORT QProcessEnvironment
|
|
69 |
{
|
|
70 |
public:
|
|
71 |
QProcessEnvironment();
|
|
72 |
QProcessEnvironment(const QProcessEnvironment &other);
|
|
73 |
~QProcessEnvironment();
|
|
74 |
QProcessEnvironment &operator=(const QProcessEnvironment &other);
|
|
75 |
|
|
76 |
bool operator==(const QProcessEnvironment &other) const;
|
|
77 |
inline bool operator!=(const QProcessEnvironment &other) const
|
|
78 |
{ return !(*this == other); }
|
|
79 |
|
|
80 |
bool isEmpty() const;
|
|
81 |
void clear();
|
|
82 |
|
|
83 |
bool contains(const QString &name) const;
|
|
84 |
void insert(const QString &name, const QString &value);
|
|
85 |
void remove(const QString &name);
|
|
86 |
QString value(const QString &name, const QString &defaultValue = QString()) const;
|
|
87 |
|
|
88 |
QStringList toStringList() const;
|
|
89 |
|
|
90 |
static QProcessEnvironment systemEnvironment();
|
|
91 |
|
|
92 |
private:
|
|
93 |
friend class QProcessPrivate;
|
|
94 |
friend class QProcessEnvironmentPrivate;
|
|
95 |
QSharedDataPointer<QProcessEnvironmentPrivate> d;
|
|
96 |
};
|
|
97 |
|
|
98 |
class Q_CORE_EXPORT QProcess : public QIODevice
|
|
99 |
{
|
|
100 |
Q_OBJECT
|
|
101 |
public:
|
|
102 |
enum ProcessError {
|
|
103 |
FailedToStart, //### file not found, resource error
|
|
104 |
Crashed,
|
|
105 |
Timedout,
|
|
106 |
ReadError,
|
|
107 |
WriteError,
|
|
108 |
UnknownError
|
|
109 |
};
|
|
110 |
enum ProcessState {
|
|
111 |
NotRunning,
|
|
112 |
Starting,
|
|
113 |
Running
|
|
114 |
};
|
|
115 |
enum ProcessChannel {
|
|
116 |
StandardOutput,
|
|
117 |
StandardError
|
|
118 |
};
|
|
119 |
enum ProcessChannelMode {
|
|
120 |
SeparateChannels,
|
|
121 |
MergedChannels,
|
|
122 |
ForwardedChannels
|
|
123 |
};
|
|
124 |
enum ExitStatus {
|
|
125 |
NormalExit,
|
|
126 |
CrashExit
|
|
127 |
};
|
|
128 |
|
|
129 |
explicit QProcess(QObject *parent = 0);
|
|
130 |
virtual ~QProcess();
|
|
131 |
|
|
132 |
void start(const QString &program, const QStringList &arguments, OpenMode mode = ReadWrite);
|
|
133 |
void start(const QString &program, OpenMode mode = ReadWrite);
|
|
134 |
|
|
135 |
ProcessChannelMode readChannelMode() const;
|
|
136 |
void setReadChannelMode(ProcessChannelMode mode);
|
|
137 |
ProcessChannelMode processChannelMode() const;
|
|
138 |
void setProcessChannelMode(ProcessChannelMode mode);
|
|
139 |
|
|
140 |
ProcessChannel readChannel() const;
|
|
141 |
void setReadChannel(ProcessChannel channel);
|
|
142 |
|
|
143 |
void closeReadChannel(ProcessChannel channel);
|
|
144 |
void closeWriteChannel();
|
|
145 |
|
|
146 |
void setStandardInputFile(const QString &fileName);
|
|
147 |
void setStandardOutputFile(const QString &fileName, OpenMode mode = Truncate);
|
|
148 |
void setStandardErrorFile(const QString &fileName, OpenMode mode = Truncate);
|
|
149 |
void setStandardOutputProcess(QProcess *destination);
|
|
150 |
|
|
151 |
QString workingDirectory() const;
|
|
152 |
void setWorkingDirectory(const QString &dir);
|
|
153 |
|
|
154 |
void setEnvironment(const QStringList &environment);
|
|
155 |
QStringList environment() const;
|
|
156 |
void setProcessEnvironment(const QProcessEnvironment &environment);
|
|
157 |
QProcessEnvironment processEnvironment() const;
|
|
158 |
|
|
159 |
QProcess::ProcessError error() const;
|
|
160 |
QProcess::ProcessState state() const;
|
|
161 |
|
|
162 |
// #### Qt 5: Q_PID is a pointer on Windows and a value on Unix
|
|
163 |
Q_PID pid() const;
|
|
164 |
|
|
165 |
bool waitForStarted(int msecs = 30000);
|
|
166 |
bool waitForReadyRead(int msecs = 30000);
|
|
167 |
bool waitForBytesWritten(int msecs = 30000);
|
|
168 |
bool waitForFinished(int msecs = 30000);
|
|
169 |
|
|
170 |
QByteArray readAllStandardOutput();
|
|
171 |
QByteArray readAllStandardError();
|
|
172 |
|
|
173 |
int exitCode() const;
|
|
174 |
QProcess::ExitStatus exitStatus() const;
|
|
175 |
|
|
176 |
// QIODevice
|
|
177 |
qint64 bytesAvailable() const;
|
|
178 |
qint64 bytesToWrite() const;
|
|
179 |
bool isSequential() const;
|
|
180 |
bool canReadLine() const;
|
|
181 |
void close();
|
|
182 |
bool atEnd() const;
|
|
183 |
|
|
184 |
static int execute(const QString &program, const QStringList &arguments);
|
|
185 |
static int execute(const QString &program);
|
|
186 |
|
|
187 |
static bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory,
|
|
188 |
qint64 *pid = 0);
|
|
189 |
static bool startDetached(const QString &program, const QStringList &arguments);
|
|
190 |
static bool startDetached(const QString &program);
|
|
191 |
|
|
192 |
static QStringList systemEnvironment();
|
|
193 |
|
|
194 |
public Q_SLOTS:
|
|
195 |
void terminate();
|
|
196 |
void kill();
|
|
197 |
|
|
198 |
Q_SIGNALS:
|
|
199 |
void started();
|
|
200 |
void finished(int exitCode);
|
|
201 |
void finished(int exitCode, QProcess::ExitStatus exitStatus);
|
|
202 |
void error(QProcess::ProcessError error);
|
|
203 |
void stateChanged(QProcess::ProcessState state);
|
|
204 |
|
|
205 |
void readyReadStandardOutput();
|
|
206 |
void readyReadStandardError();
|
|
207 |
|
|
208 |
protected:
|
|
209 |
void setProcessState(ProcessState state);
|
|
210 |
|
|
211 |
virtual void setupChildProcess();
|
|
212 |
|
|
213 |
// QIODevice
|
|
214 |
qint64 readData(char *data, qint64 maxlen);
|
|
215 |
qint64 writeData(const char *data, qint64 len);
|
|
216 |
|
|
217 |
private:
|
|
218 |
Q_DECLARE_PRIVATE(QProcess)
|
|
219 |
Q_DISABLE_COPY(QProcess)
|
|
220 |
|
|
221 |
Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardOutput())
|
|
222 |
Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardError())
|
|
223 |
Q_PRIVATE_SLOT(d_func(), bool _q_canWrite())
|
|
224 |
Q_PRIVATE_SLOT(d_func(), bool _q_startupNotification())
|
|
225 |
Q_PRIVATE_SLOT(d_func(), bool _q_processDied())
|
|
226 |
Q_PRIVATE_SLOT(d_func(), void _q_notified())
|
|
227 |
friend class QProcessManager;
|
|
228 |
};
|
|
229 |
|
|
230 |
#endif // QT_NO_PROCESS
|
|
231 |
|
|
232 |
QT_END_NAMESPACE
|
|
233 |
|
|
234 |
QT_END_HEADER
|
|
235 |
|
|
236 |
#endif // QPROCESS_H
|