Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qprocess.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | QStringList QProcessEnvironmentPrivate::toList() const | - | ||||||||||||||||||
12 | { | - | ||||||||||||||||||
13 | QStringList result; | - | ||||||||||||||||||
14 | result.reserve(hash.size()); | - | ||||||||||||||||||
15 | for (Hash::const_iterator it = hash.cbegin(), end = hash.cend(); it != end; ++it) | - | ||||||||||||||||||
16 | result << nameToString(it.key()) + QLatin1Char('=') + valueToString(it.value()); | - | ||||||||||||||||||
17 | return result; | - | ||||||||||||||||||
18 | } | - | ||||||||||||||||||
19 | - | |||||||||||||||||||
20 | QProcessEnvironment QProcessEnvironmentPrivate::fromList(const QStringList &list) | - | ||||||||||||||||||
21 | { | - | ||||||||||||||||||
22 | QProcessEnvironment env; | - | ||||||||||||||||||
23 | QStringList::ConstIterator it = list.constBegin(), | - | ||||||||||||||||||
24 | end = list.constEnd(); | - | ||||||||||||||||||
25 | for ( ; it != end; ++it) { | - | ||||||||||||||||||
26 | int pos = it->indexOf(QLatin1Char('='), 1); | - | ||||||||||||||||||
27 | if (pos < 1) | - | ||||||||||||||||||
28 | continue; | - | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | QString value = it->mid(pos + 1); | - | ||||||||||||||||||
31 | QString name = *it; | - | ||||||||||||||||||
32 | name.truncate(pos); | - | ||||||||||||||||||
33 | env.insert(name, value); | - | ||||||||||||||||||
34 | } | - | ||||||||||||||||||
35 | return env; | - | ||||||||||||||||||
36 | } | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | QStringList QProcessEnvironmentPrivate::keys() const | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | QStringList result; | - | ||||||||||||||||||
41 | result.reserve(hash.size()); | - | ||||||||||||||||||
42 | Hash::ConstIterator it = hash.constBegin(), | - | ||||||||||||||||||
43 | end = hash.constEnd(); | - | ||||||||||||||||||
44 | for ( ; it != end; ++it) | - | ||||||||||||||||||
45 | result << nameToString(it.key()); | - | ||||||||||||||||||
46 | return result; | - | ||||||||||||||||||
47 | } | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other) | - | ||||||||||||||||||
50 | { | - | ||||||||||||||||||
51 | Hash::ConstIterator it = other.hash.constBegin(), | - | ||||||||||||||||||
52 | end = other.hash.constEnd(); | - | ||||||||||||||||||
53 | for ( ; it != end; ++it) | - | ||||||||||||||||||
54 | hash.insert(it.key(), it.value()); | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | - | |||||||||||||||||||
57 | QHash<QString, Key>::ConstIterator nit = other.nameMap.constBegin(), | - | ||||||||||||||||||
58 | nend = other.nameMap.constEnd(); | - | ||||||||||||||||||
59 | for ( ; nit != nend; ++nit) | - | ||||||||||||||||||
60 | nameMap.insert(nit.key(), nit.value()); | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | } | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | - | |||||||||||||||||||
65 | - | |||||||||||||||||||
66 | - | |||||||||||||||||||
67 | - | |||||||||||||||||||
68 | - | |||||||||||||||||||
69 | QProcessEnvironment::QProcessEnvironment() | - | ||||||||||||||||||
70 | : d(0) | - | ||||||||||||||||||
71 | { | - | ||||||||||||||||||
72 | } | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | - | |||||||||||||||||||
75 | - | |||||||||||||||||||
76 | - | |||||||||||||||||||
77 | QProcessEnvironment::~QProcessEnvironment() | - | ||||||||||||||||||
78 | { | - | ||||||||||||||||||
79 | } | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | - | |||||||||||||||||||
82 | - | |||||||||||||||||||
83 | - | |||||||||||||||||||
84 | QProcessEnvironment::QProcessEnvironment(const QProcessEnvironment &other) | - | ||||||||||||||||||
85 | : d(other.d) | - | ||||||||||||||||||
86 | { | - | ||||||||||||||||||
87 | } | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | - | |||||||||||||||||||
90 | - | |||||||||||||||||||
91 | - | |||||||||||||||||||
92 | - | |||||||||||||||||||
93 | QProcessEnvironment &QProcessEnvironment::operator=(const QProcessEnvironment &other) | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | d = other.d; | - | ||||||||||||||||||
96 | return *this; | - | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const | - | ||||||||||||||||||
99 | { | - | ||||||||||||||||||
100 | if (d == other.d) | - | ||||||||||||||||||
101 | return true; | - | ||||||||||||||||||
102 | if (d) { | - | ||||||||||||||||||
103 | if (other.d) { | - | ||||||||||||||||||
104 | QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d); | - | ||||||||||||||||||
105 | return d->hash == other.d->hash; | - | ||||||||||||||||||
106 | } else { | - | ||||||||||||||||||
107 | return isEmpty(); | - | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | } else { | - | ||||||||||||||||||
110 | return other.isEmpty(); | - | ||||||||||||||||||
111 | } | - | ||||||||||||||||||
112 | } | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | - | |||||||||||||||||||
115 | - | |||||||||||||||||||
116 | - | |||||||||||||||||||
117 | - | |||||||||||||||||||
118 | - | |||||||||||||||||||
119 | - | |||||||||||||||||||
120 | bool QProcessEnvironment::isEmpty() const | - | ||||||||||||||||||
121 | { | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | return d ? d->hash.isEmpty() : true; | - | ||||||||||||||||||
124 | } | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | - | |||||||||||||||||||
127 | - | |||||||||||||||||||
128 | - | |||||||||||||||||||
129 | - | |||||||||||||||||||
130 | - | |||||||||||||||||||
131 | - | |||||||||||||||||||
132 | void QProcessEnvironment::clear() | - | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | if (d) | - | ||||||||||||||||||
135 | d->hash.clear(); | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | - | |||||||||||||||||||
138 | } | - | ||||||||||||||||||
139 | bool QProcessEnvironment::contains(const QString &name) const | - | ||||||||||||||||||
140 | { | - | ||||||||||||||||||
141 | if (!d) | - | ||||||||||||||||||
142 | return false; | - | ||||||||||||||||||
143 | QProcessEnvironmentPrivate::MutexLocker locker(d); | - | ||||||||||||||||||
144 | return d->hash.contains(d->prepareName(name)); | - | ||||||||||||||||||
145 | } | - | ||||||||||||||||||
146 | void QProcessEnvironment::insert(const QString &name, const QString &value) | - | ||||||||||||||||||
147 | { | - | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | d.detach(); | - | ||||||||||||||||||
150 | d->hash.insert(d->prepareName(name), d->prepareValue(value)); | - | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | void QProcessEnvironment::remove(const QString &name) | - | ||||||||||||||||||
153 | { | - | ||||||||||||||||||
154 | if (d) { | - | ||||||||||||||||||
155 | d.detach(); | - | ||||||||||||||||||
156 | d->hash.remove(d->prepareName(name)); | - | ||||||||||||||||||
157 | } | - | ||||||||||||||||||
158 | } | - | ||||||||||||||||||
159 | QString QProcessEnvironment::value(const QString &name, const QString &defaultValue) const | - | ||||||||||||||||||
160 | { | - | ||||||||||||||||||
161 | if (!d) | - | ||||||||||||||||||
162 | return defaultValue; | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | QProcessEnvironmentPrivate::MutexLocker locker(d); | - | ||||||||||||||||||
165 | QProcessEnvironmentPrivate::Hash::ConstIterator it = d->hash.constFind(d->prepareName(name)); | - | ||||||||||||||||||
166 | if (it == d->hash.constEnd()) | - | ||||||||||||||||||
167 | return defaultValue; | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | return d->valueToString(it.value()); | - | ||||||||||||||||||
170 | } | - | ||||||||||||||||||
171 | QStringList QProcessEnvironment::toStringList() const | - | ||||||||||||||||||
172 | { | - | ||||||||||||||||||
173 | if (!d) | - | ||||||||||||||||||
174 | return QStringList(); | - | ||||||||||||||||||
175 | QProcessEnvironmentPrivate::MutexLocker locker(d); | - | ||||||||||||||||||
176 | return d->toList(); | - | ||||||||||||||||||
177 | } | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | - | |||||||||||||||||||
180 | - | |||||||||||||||||||
181 | - | |||||||||||||||||||
182 | - | |||||||||||||||||||
183 | - | |||||||||||||||||||
184 | - | |||||||||||||||||||
185 | QStringList QProcessEnvironment::keys() const | - | ||||||||||||||||||
186 | { | - | ||||||||||||||||||
187 | if (!d) | - | ||||||||||||||||||
188 | return QStringList(); | - | ||||||||||||||||||
189 | QProcessEnvironmentPrivate::MutexLocker locker(d); | - | ||||||||||||||||||
190 | return d->keys(); | - | ||||||||||||||||||
191 | } | - | ||||||||||||||||||
192 | void QProcessEnvironment::insert(const QProcessEnvironment &e) | - | ||||||||||||||||||
193 | { | - | ||||||||||||||||||
194 | if (!e.d) | - | ||||||||||||||||||
195 | return; | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | - | |||||||||||||||||||
198 | QProcessEnvironmentPrivate::MutexLocker locker(e.d); | - | ||||||||||||||||||
199 | d->insert(*e.d); | - | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | void QProcessPrivate::Channel::clear() | - | ||||||||||||||||||
203 | { | - | ||||||||||||||||||
204 | switch (type) { | - | ||||||||||||||||||
205 | case PipeSource: | - | ||||||||||||||||||
206 | ((!(process)) ? qt_assert("process",__FILE__,438440) : qt_noop()); | - | ||||||||||||||||||
207 | process->stdinChannel.type = Normal; | - | ||||||||||||||||||
208 | process->stdinChannel.process = 0; | - | ||||||||||||||||||
209 | break; | - | ||||||||||||||||||
210 | case PipeSink: | - | ||||||||||||||||||
211 | ((!(process)) ? qt_assert("process",__FILE__,443445) : qt_noop()); | - | ||||||||||||||||||
212 | process->stdoutChannel.type = Normal; | - | ||||||||||||||||||
213 | process->stdoutChannel.process = 0; | - | ||||||||||||||||||
214 | break; | - | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | type = Normal; | - | ||||||||||||||||||
218 | file.clear(); | - | ||||||||||||||||||
219 | process = 0; | - | ||||||||||||||||||
220 | } | - | ||||||||||||||||||
221 | QProcessPrivate::QProcessPrivate() | - | ||||||||||||||||||
222 | { | - | ||||||||||||||||||
223 | processChannelreadBufferChunkSize = QProcess::StandardOutput4096; | - | ||||||||||||||||||
224 | writeBufferChunkSize = 4096; | - | ||||||||||||||||||
225 | processChannelMode = QProcess::SeparateChannels; | - | ||||||||||||||||||
226 | inputChannelMode = QProcess::ManagedInputChannel; | - | ||||||||||||||||||
227 | processError = QProcess::UnknownError; | - | ||||||||||||||||||
228 | processState = QProcess::NotRunning; | - | ||||||||||||||||||
229 | pid = 0; | - | ||||||||||||||||||
230 | sequenceNumber = 0; | - | ||||||||||||||||||
231 | exitCode = 0; | - | ||||||||||||||||||
232 | exitStatus = QProcess::NormalExit; | - | ||||||||||||||||||
233 | startupSocketNotifier = 0; | - | ||||||||||||||||||
234 | deathNotifier = 0; | - | ||||||||||||||||||
235 | childStartedPipe[0] = -1; | - | ||||||||||||||||||
236 | childStartedPipe[1] = -1; | - | ||||||||||||||||||
237 | forkfd = -1; | - | ||||||||||||||||||
exitCode = 0; | ||||||||||||||||||||
238 | crashed = false; | - | ||||||||||||||||||
239 | dying = false; | - | ||||||||||||||||||
240 | emittedReadyRead = false; | - | ||||||||||||||||||
241 | emittedBytesWritten = false; | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | - | |||||||||||||||||||
244 | - | |||||||||||||||||||
245 | - | |||||||||||||||||||
246 | } executed 2280 times by 35 tests: end of block Executed by:
| 2280 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | - | |||||||||||||||||||
249 | - | |||||||||||||||||||
250 | - | |||||||||||||||||||
251 | QProcessPrivate::~QProcessPrivate() | - | ||||||||||||||||||
252 | { | - | ||||||||||||||||||
253 | if (stdinChannel.process) | - | ||||||||||||||||||
254 | stdinChannel.process->stdoutChannel.clear(); | - | ||||||||||||||||||
255 | if (stdoutChannel.process) | - | ||||||||||||||||||
256 | stdoutChannel.process->stdinChannel.clear(); | - | ||||||||||||||||||
257 | } | - | ||||||||||||||||||
258 | - | |||||||||||||||||||
259 | - | |||||||||||||||||||
260 | - | |||||||||||||||||||
261 | - | |||||||||||||||||||
262 | void QProcessPrivate::cleanup() | - | ||||||||||||||||||
263 | { | - | ||||||||||||||||||
264 | q_func()->setProcessState(QProcess::NotRunning); | - | ||||||||||||||||||
265 | pid = 0; | - | ||||||||||||||||||
266 | sequenceNumber = 0; | - | ||||||||||||||||||
267 | dying = false; | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | if (stdoutChannel.notifier) { | - | ||||||||||||||||||
270 | delete stdoutChannel.notifier; | - | ||||||||||||||||||
271 | stdoutChannel.notifier = 0; | - | ||||||||||||||||||
272 | } | - | ||||||||||||||||||
273 | if (stderrChannel.notifier) { | - | ||||||||||||||||||
274 | delete stderrChannel.notifier; | - | ||||||||||||||||||
275 | stderrChannel.notifier = 0; | - | ||||||||||||||||||
276 | } | - | ||||||||||||||||||
277 | if (stdinChannel.notifier) { | - | ||||||||||||||||||
278 | delete stdinChannel.notifier; | - | ||||||||||||||||||
279 | stdinChannel.notifier = 0; | - | ||||||||||||||||||
280 | } | - | ||||||||||||||||||
281 | if (startupSocketNotifier) { | - | ||||||||||||||||||
282 | delete startupSocketNotifier; | - | ||||||||||||||||||
283 | startupSocketNotifier = 0; | - | ||||||||||||||||||
284 | } | - | ||||||||||||||||||
285 | if (deathNotifier) { | - | ||||||||||||||||||
286 | delete deathNotifier; | - | ||||||||||||||||||
287 | deathNotifier = 0; | - | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | closeChannel(&stdoutChannel); | - | ||||||||||||||||||
290 | closeChannel(&stderrChannel); | - | ||||||||||||||||||
291 | closeChannel(&stdinChannel); | - | ||||||||||||||||||
292 | destroyPipe(childStartedPipe); | - | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | if (forkfd != -1) | - | ||||||||||||||||||
295 | qt_safe_close(forkfd); | - | ||||||||||||||||||
296 | forkfd = -1; | - | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | - | |||||||||||||||||||
301 | - | |||||||||||||||||||
302 | - | |||||||||||||||||||
303 | void QProcessPrivate::setError(QProcess::ProcessError error, const QString &description) | - | ||||||||||||||||||
304 | { | - | ||||||||||||||||||
305 | processError = error; | - | ||||||||||||||||||
306 | if (description.isEmpty()) { | - | ||||||||||||||||||
307 | switch (error) { | - | ||||||||||||||||||
308 | case QProcess::FailedToStart: | - | ||||||||||||||||||
309 | errorString = QProcess::tr("Process failed to start"); | - | ||||||||||||||||||
310 | break; | - | ||||||||||||||||||
311 | case QProcess::Crashed: | - | ||||||||||||||||||
312 | errorString = QProcess::tr("Process crashed"); | - | ||||||||||||||||||
313 | break; | - | ||||||||||||||||||
314 | case QProcess::Timedout: | - | ||||||||||||||||||
315 | errorString = QProcess::tr("Process operation timed out"); | - | ||||||||||||||||||
316 | break; | - | ||||||||||||||||||
317 | case QProcess::ReadError: | - | ||||||||||||||||||
318 | errorString = QProcess::tr("Error reading from process"); | - | ||||||||||||||||||
319 | break; | - | ||||||||||||||||||
320 | case QProcess::WriteError: | - | ||||||||||||||||||
321 | errorString = QProcess::tr("Error writing to process"); | - | ||||||||||||||||||
322 | break; | - | ||||||||||||||||||
323 | case QProcess::UnknownError: | - | ||||||||||||||||||
324 | errorString.clear(); | - | ||||||||||||||||||
325 | break; | - | ||||||||||||||||||
326 | } | - | ||||||||||||||||||
327 | } else { | - | ||||||||||||||||||
328 | errorString = description; | - | ||||||||||||||||||
329 | } | - | ||||||||||||||||||
330 | } | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | - | |||||||||||||||||||
333 | - | |||||||||||||||||||
334 | - | |||||||||||||||||||
335 | void QProcessPrivate::setErrorAndEmit(QProcess::ProcessError error, const QString &description) | - | ||||||||||||||||||
336 | { | - | ||||||||||||||||||
337 | QProcess * const q = q_func(); | - | ||||||||||||||||||
338 | ((!(error != QProcess::UnknownError)) ? qt_assert("error != QProcess::UnknownError",__FILE__,956996) : qt_noop()); | - | ||||||||||||||||||
339 | setError(error, description); | - | ||||||||||||||||||
340 | q->errorOccurred(processError); | - | ||||||||||||||||||
341 | q->error(processError); | - | ||||||||||||||||||
342 | } | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | - | |||||||||||||||||||
345 | - | |||||||||||||||||||
346 | - | |||||||||||||||||||
347 | - | |||||||||||||||||||
348 | bool QProcessPrivate::tryReadFromChannel(Channel *channel) | - | ||||||||||||||||||
349 | { | - | ||||||||||||||||||
350 | QProcess * const q = q_func(); | - | ||||||||||||||||||
351 | if (channel->pipe[0] == -1
| 4635-37468 | ||||||||||||||||||
352 | return executed 4635 times by 30 tests: false;return false; Executed by:
executed 4635 times by 30 tests: return false; Executed by:
| 4635 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | qint64 available = bytesAvailableInChannel(channel); | - | ||||||||||||||||||
355 | if (available == 0
| 4607-32861 | ||||||||||||||||||
356 | available = 1; executed 4607 times by 30 tests: available = 1; Executed by:
| 4607 | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | QProcess::ProcessChannel channelIdx = (channel == &stdoutChannel
| 3097-34371 | ||||||||||||||||||
359 | ? QProcess::StandardOutput | - | ||||||||||||||||||
360 | : QProcess::StandardError); | - | ||||||||||||||||||
361 | ((!(readBuffers.size() > int(channelIdx))) ? qt_assert("readBuffers.size() > int(channelIdx)",__FILE__,1019) : qt_noop()); | - | ||||||||||||||||||
362 | QRingBuffer &readBuffer = readBuffers[int(channelIdx)]; | - | ||||||||||||||||||
363 | char *ptr = channel->bufferreadBuffer.reserve(available); | - | ||||||||||||||||||
364 | qint64 readBytes = readFromChannel(channel, ptr, available); | - | ||||||||||||||||||
365 | if (readBytes <= 0
| 4607-32861 | ||||||||||||||||||
366 | channel->bufferreadBuffer executed 4607 times by 30 tests: .chop(available);readBuffer.chop(available); Executed by:
executed 4607 times by 30 tests: readBuffer.chop(available); Executed by:
| 4607 | ||||||||||||||||||
367 | if (readBytes == -2
| 0-37468 | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
370 | } | - | ||||||||||||||||||
371 | if (readBytes == -1
| 0-37468 | ||||||||||||||||||
372 | setErrorAndEmit(QProcess::ReadError); | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | - | |||||||||||||||||||
375 | - | |||||||||||||||||||
376 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | if (readBytes == 0
| 4607-32861 | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | if (channel->notifier
| 162-4445 | ||||||||||||||||||
381 | channel->notifier->setEnabled(false); executed 4445 times by 28 tests: channel->notifier->setEnabled(false); Executed by:
| 4445 | ||||||||||||||||||
382 | closeChannel(channel); | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | - | |||||||||||||||||||
385 | - | |||||||||||||||||||
386 | return executed 4607 times by 30 tests: false;return false; Executed by:
executed 4607 times by 30 tests: return false; Executed by:
| 4607 | ||||||||||||||||||
387 | } | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | - | |||||||||||||||||||
390 | - | |||||||||||||||||||
391 | - | |||||||||||||||||||
392 | - | |||||||||||||||||||
393 | if (channel->closed
| 40-32821 | ||||||||||||||||||
394 | channel->bufferreadBuffer.chop(readBytes); | - | ||||||||||||||||||
395 | return executed 40 times by 1 test: false;return false; Executed by:
executed 40 times by 1 test: return false; Executed by:
| 40 | ||||||||||||||||||
396 | } | - | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | channel->bufferreadBuffer.chop(available - readBytes); | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | bool didRead = false; | - | ||||||||||||||||||
bool isStdout = channel == &stdoutChannel; | ||||||||||||||||||||
401 | if (readBytes == 0
| 0-32821 | ||||||||||||||||||
402 | if (channel->notifier
| 0 | ||||||||||||||||||
403 | channel->notifier->setEnabled(false); never executed: channel->notifier->setEnabled(false); | 0 | ||||||||||||||||||
404 | } never executed: else if ((processChannel == QProcess::StandardOutput)(currentReadChannelend of block
| 0-31666 | ||||||||||||||||||
405 | didRead = true; | - | ||||||||||||||||||
406 | if (!emittedReadyRead
| 1-31665 | ||||||||||||||||||
407 | emittedReadyRead = true; | - | ||||||||||||||||||
408 | q->readyRead(); | - | ||||||||||||||||||
409 | emittedReadyRead = false; | - | ||||||||||||||||||
410 | } executed 31665 times by 22 tests: end of block Executed by:
| 31665 | ||||||||||||||||||
411 | } executed 31666 times by 22 tests: end of block Executed by:
| 31666 | ||||||||||||||||||
412 | q->channelReadyRead(int(channelIdx)); | - | ||||||||||||||||||
413 | if (isStdoutchannelIdx == QProcess::StandardOutput
| 779-32042 | ||||||||||||||||||
414 | q->readyReadStandardOutput(QProcess::QPrivateSignal()); executed 32042 times by 22 tests: q->readyReadStandardOutput(QProcess::QPrivateSignal()); Executed by:
| 32042 | ||||||||||||||||||
415 | else | - | ||||||||||||||||||
416 | q->readyReadStandardError(QProcess::QPrivateSignal()); executed 779 times by 11 tests: q->readyReadStandardError(QProcess::QPrivateSignal()); Executed by:
| 779 | ||||||||||||||||||
417 | return executed 32821 times by 26 tests: didRead;return didRead; Executed by:
executed 32821 times by 26 tests: return didRead; Executed by:
| 32821 | ||||||||||||||||||
418 | } | - | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | - | |||||||||||||||||||
421 | - | |||||||||||||||||||
422 | - | |||||||||||||||||||
423 | bool QProcessPrivate::_q_canReadStandardOutput() | - | ||||||||||||||||||
424 | { | - | ||||||||||||||||||
425 | return tryReadFromChannel(&stdoutChannel); | - | ||||||||||||||||||
426 | } | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | - | |||||||||||||||||||
429 | - | |||||||||||||||||||
430 | - | |||||||||||||||||||
431 | bool QProcessPrivate::_q_canReadStandardError() | - | ||||||||||||||||||
432 | { | - | ||||||||||||||||||
433 | return tryReadFromChannel(&stderrChannel); | - | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | - | |||||||||||||||||||
437 | - | |||||||||||||||||||
438 | - | |||||||||||||||||||
439 | bool QProcessPrivate::_q_canWrite() | - | ||||||||||||||||||
440 | { | - | ||||||||||||||||||
441 | if (stdinChannel.notifier
| 0-3630 | ||||||||||||||||||
442 | stdinChannel.notifier->setEnabled(false); executed 3630 times by 6 tests: stdinChannel.notifier->setEnabled(false); Executed by:
| 3630 | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | if (stdinChannel.bufferwriteBuffer
| 0-3630 | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | - | |||||||||||||||||||
447 | - | |||||||||||||||||||
448 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
449 | } | - | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | const bool writeSucceeded = writeToStdin(); | - | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | if (stdinChannel.notifier
| 0-3630 | ||||||||||||||||||
454 | stdinChannel.notifier->setEnabled(true); executed 2715 times by 2 tests: stdinChannel.notifier->setEnabled(true); Executed by:
| 2715 | ||||||||||||||||||
455 | if (stdinChannel.bufferwriteBuffer
| 456-2715 | ||||||||||||||||||
456 | closeWriteChannel(); executed 459 times by 3 tests: closeWriteChannel(); Executed by:
| 459 | ||||||||||||||||||
457 | return executed 3630 times by 6 tests: writeSucceeded;return writeSucceeded; Executed by:
executed 3630 times by 6 tests: return writeSucceeded; Executed by:
| 3630 | ||||||||||||||||||
458 | } | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | - | |||||||||||||||||||
461 | - | |||||||||||||||||||
462 | - | |||||||||||||||||||
463 | bool QProcessPrivate::_q_processDied() | - | ||||||||||||||||||
464 | { | - | ||||||||||||||||||
465 | QProcess * const q = q_func(); | - | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | - | |||||||||||||||||||
468 | - | |||||||||||||||||||
469 | - | |||||||||||||||||||
470 | if (!waitForDeadChild()) | - | ||||||||||||||||||
471 | return false; | - | ||||||||||||||||||
472 | if (processState == QProcess::Starting) { | - | ||||||||||||||||||
473 | if (!_q_startupNotification()) | - | ||||||||||||||||||
474 | return true; | - | ||||||||||||||||||
475 | } | - | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | if (dying) { | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | - | |||||||||||||||||||
480 | - | |||||||||||||||||||
481 | - | |||||||||||||||||||
482 | return true; | - | ||||||||||||||||||
483 | } | - | ||||||||||||||||||
484 | dying = true; | - | ||||||||||||||||||
485 | - | |||||||||||||||||||
486 | - | |||||||||||||||||||
487 | - | |||||||||||||||||||
488 | - | |||||||||||||||||||
489 | _q_canReadStandardOutput(); | - | ||||||||||||||||||
490 | _q_canReadStandardError(); | - | ||||||||||||||||||
491 | - | |||||||||||||||||||
492 | findExitCode(); | - | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | if (crashed) { | - | ||||||||||||||||||
495 | exitStatus = QProcess::CrashExit; | - | ||||||||||||||||||
496 | setErrorAndEmit(QProcess::Crashed); | - | ||||||||||||||||||
497 | } | - | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | bool wasRunning = (processState == QProcess::Running); | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | cleanup(); | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | if (wasRunning) { | - | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | q->readChannelFinished(); | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | - | |||||||||||||||||||
508 | - | |||||||||||||||||||
509 | - | |||||||||||||||||||
510 | q->finished(exitCode); | - | ||||||||||||||||||
511 | q->finished(exitCode, exitStatus); | - | ||||||||||||||||||
512 | } | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | - | |||||||||||||||||||
515 | - | |||||||||||||||||||
516 | return true; | - | ||||||||||||||||||
517 | } | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | - | |||||||||||||||||||
520 | - | |||||||||||||||||||
521 | - | |||||||||||||||||||
522 | bool QProcessPrivate::_q_startupNotification() | - | ||||||||||||||||||
523 | { | - | ||||||||||||||||||
524 | QProcess * const q = q_func(); | - | ||||||||||||||||||
525 | - | |||||||||||||||||||
526 | - | |||||||||||||||||||
527 | - | |||||||||||||||||||
528 | - | |||||||||||||||||||
529 | if (startupSocketNotifier) | - | ||||||||||||||||||
530 | startupSocketNotifier->setEnabled(false); | - | ||||||||||||||||||
531 | QString errorMessage; | - | ||||||||||||||||||
532 | if (processStarted(&errorMessage)) { | - | ||||||||||||||||||
533 | q->setProcessState(QProcess::Running); | - | ||||||||||||||||||
534 | q->started(QProcess::QPrivateSignal()); | - | ||||||||||||||||||
535 | return true; | - | ||||||||||||||||||
536 | } | - | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | q->setProcessState(QProcess::NotRunning); | - | ||||||||||||||||||
539 | setErrorAndEmit(QProcess::FailedToStart, errorMessage); | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | - | |||||||||||||||||||
542 | waitForDeadChild(); | - | ||||||||||||||||||
543 | findExitCode(); | - | ||||||||||||||||||
544 | - | |||||||||||||||||||
545 | cleanup(); | - | ||||||||||||||||||
546 | return false; | - | ||||||||||||||||||
547 | } | - | ||||||||||||||||||
548 | - | |||||||||||||||||||
549 | - | |||||||||||||||||||
550 | - | |||||||||||||||||||
551 | - | |||||||||||||||||||
552 | void QProcessPrivate::closeWriteChannel() | - | ||||||||||||||||||
553 | { | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | - | |||||||||||||||||||
556 | - | |||||||||||||||||||
557 | if (stdinChannel.notifier) { | - | ||||||||||||||||||
558 | delete stdinChannel.notifier; | - | ||||||||||||||||||
559 | stdinChannel.notifier = 0; | - | ||||||||||||||||||
560 | } | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | - | |||||||||||||||||||
563 | - | |||||||||||||||||||
564 | - | |||||||||||||||||||
565 | - | |||||||||||||||||||
566 | closeChannel(&stdinChannel); | - | ||||||||||||||||||
567 | } | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | - | |||||||||||||||||||
570 | - | |||||||||||||||||||
571 | - | |||||||||||||||||||
572 | QProcess::QProcess(QObject *parent) | - | ||||||||||||||||||
573 | : QIODevice(*new QProcessPrivate, parent) | - | ||||||||||||||||||
574 | { | - | ||||||||||||||||||
575 | - | |||||||||||||||||||
576 | - | |||||||||||||||||||
577 | - | |||||||||||||||||||
578 | } | - | ||||||||||||||||||
579 | - | |||||||||||||||||||
580 | - | |||||||||||||||||||
581 | - | |||||||||||||||||||
582 | - | |||||||||||||||||||
583 | - | |||||||||||||||||||
584 | - | |||||||||||||||||||
585 | - | |||||||||||||||||||
586 | QProcess::~QProcess() | - | ||||||||||||||||||
587 | { | - | ||||||||||||||||||
588 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
589 | if (d->processState != NotRunning) { | - | ||||||||||||||||||
590 | QMessageLogger(__FILE__, 12131258, __PRETTY_FUNCTION__).warning().nospace() | - | ||||||||||||||||||
591 | << "QProcess: Destroyed while process (" << QDir::toNativeSeparators(program()) << ") is still running."; | - | ||||||||||||||||||
592 | kill(); | - | ||||||||||||||||||
593 | waitForFinished(); | - | ||||||||||||||||||
594 | } | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | - | |||||||||||||||||||
597 | d->findExitCode(); | - | ||||||||||||||||||
598 | - | |||||||||||||||||||
599 | d->cleanup(); | - | ||||||||||||||||||
600 | } | - | ||||||||||||||||||
601 | QProcess::ProcessChannelMode QProcess::readChannelMode() const | - | ||||||||||||||||||
602 | { | - | ||||||||||||||||||
603 | return processChannelMode(); | - | ||||||||||||||||||
604 | } | - | ||||||||||||||||||
605 | void QProcess::setReadChannelMode(ProcessChannelMode mode) | - | ||||||||||||||||||
606 | { | - | ||||||||||||||||||
607 | setProcessChannelMode(mode); | - | ||||||||||||||||||
608 | } | - | ||||||||||||||||||
609 | QProcess::ProcessChannelMode QProcess::processChannelMode() const | - | ||||||||||||||||||
610 | { | - | ||||||||||||||||||
611 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
612 | return d->processChannelMode; | - | ||||||||||||||||||
613 | } | - | ||||||||||||||||||
614 | void QProcess::setProcessChannelMode(ProcessChannelMode mode) | - | ||||||||||||||||||
615 | { | - | ||||||||||||||||||
616 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
617 | d->processChannelMode = mode; | - | ||||||||||||||||||
618 | } | - | ||||||||||||||||||
619 | QProcess::InputChannelMode QProcess::inputChannelMode() const | - | ||||||||||||||||||
620 | { | - | ||||||||||||||||||
621 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
622 | return d->inputChannelMode; | - | ||||||||||||||||||
623 | } | - | ||||||||||||||||||
624 | void QProcess::setInputChannelMode(InputChannelMode mode) | - | ||||||||||||||||||
625 | { | - | ||||||||||||||||||
626 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
627 | d->inputChannelMode = mode; | - | ||||||||||||||||||
628 | } | - | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | - | |||||||||||||||||||
631 | - | |||||||||||||||||||
632 | - | |||||||||||||||||||
633 | - | |||||||||||||||||||
634 | - | |||||||||||||||||||
635 | QProcess::ProcessChannel QProcess::readChannel() const | - | ||||||||||||||||||
636 | { | - | ||||||||||||||||||
637 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
638 | return executed 2523 times by 16 tests: ProcessChannel(d->processChannel;currentReadChannel);return ProcessChannel(d->currentReadChannel); Executed by:
executed 2523 times by 16 tests: return ProcessChannel(d->currentReadChannel); Executed by:
| 2523 | ||||||||||||||||||
639 | } | - | ||||||||||||||||||
640 | void QProcess::setReadChannel(ProcessChannel channel) | - | ||||||||||||||||||
{ | ||||||||||||||||||||
QProcessPrivate * const d = d_func(); | ||||||||||||||||||||
if (d->processChannel !=channel) | ||||||||||||||||||||
641 | { | - | ||||||||||||||||||
642 | QByteArray buf = d->buffer.readAll(); | - | ||||||||||||||||||
if (d->processChannel == QProcessQIODevice::StandardOutput) { | ||||||||||||||||||||
for (int i = buf.size() - 1; i >= 0; --i) | ||||||||||||||||||||
d->stdoutChannel.buffer.ungetChar(buf.at(i)); | ||||||||||||||||||||
} else { | ||||||||||||||||||||
forsetCurrentReadChannel(inti = buf.size() - 1; i >= 0; --i) | ||||||||||||||||||||
d->stderrChannel.buffer.ungetChar(buf.at(i)); | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
d->processChannel =channel;)); | ||||||||||||||||||||
643 | } executed 5181 times by 18 tests: end of block Executed by:
| 5181 | ||||||||||||||||||
644 | void QProcess::closeReadChannel(ProcessChannel channel) | - | ||||||||||||||||||
645 | { | - | ||||||||||||||||||
646 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | if (channel == StandardOutput) | - | ||||||||||||||||||
649 | d->stdoutChannel.closed = true; | - | ||||||||||||||||||
650 | else | - | ||||||||||||||||||
651 | d->stderrChannel.closed = true; | - | ||||||||||||||||||
652 | } | - | ||||||||||||||||||
653 | void QProcess::closeWriteChannel() | - | ||||||||||||||||||
654 | { | - | ||||||||||||||||||
655 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
656 | d->stdinChannel.closed = true; | - | ||||||||||||||||||
657 | if (d->stdinChannel.bufferwriteBuffer.isEmpty()
| 170-462 | ||||||||||||||||||
658 | d->closeWriteChannel(); executed 170 times by 6 tests: d->closeWriteChannel(); Executed by:
| 170 | ||||||||||||||||||
659 | } executed 632 times by 8 tests: end of block Executed by:
| 632 | ||||||||||||||||||
660 | void QProcess::setStandardInputFile(const QString &fileName) | - | ||||||||||||||||||
661 | { | - | ||||||||||||||||||
662 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
663 | d->stdinChannel = fileName; | - | ||||||||||||||||||
664 | } | - | ||||||||||||||||||
665 | void QProcess::setStandardOutputFile(const QString &fileName, OpenMode mode) | - | ||||||||||||||||||
666 | { | - | ||||||||||||||||||
667 | ((!(mode == Append || mode == Truncate)) ? qt_assert("mode == Append || mode == Truncate",__FILE__,14441478) : qt_noop()); | - | ||||||||||||||||||
668 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
669 | - | |||||||||||||||||||
670 | d->stdoutChannel = fileName; | - | ||||||||||||||||||
671 | d->stdoutChannel.append = mode == Append; | - | ||||||||||||||||||
672 | } | - | ||||||||||||||||||
673 | void QProcess::setStandardErrorFile(const QString &fileName, OpenMode mode) | - | ||||||||||||||||||
674 | { | - | ||||||||||||||||||
675 | ((!(mode == Append || mode == Truncate)) ? qt_assert("mode == Append || mode == Truncate",__FILE__,14711505) : qt_noop()); | - | ||||||||||||||||||
676 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | d->stderrChannel = fileName; | - | ||||||||||||||||||
679 | d->stderrChannel.append = mode == Append; | - | ||||||||||||||||||
680 | } | - | ||||||||||||||||||
681 | void QProcess::setStandardOutputProcess(QProcess *destination) | - | ||||||||||||||||||
682 | { | - | ||||||||||||||||||
683 | QProcessPrivate *dfrom = d_func(); | - | ||||||||||||||||||
684 | QProcessPrivate *dto = destination->d_func(); | - | ||||||||||||||||||
685 | dfrom->stdoutChannel.pipeTo(dto); | - | ||||||||||||||||||
686 | dto->stdinChannel.pipeFrom(dfrom); | - | ||||||||||||||||||
687 | } | - | ||||||||||||||||||
688 | QString QProcess::workingDirectory() const | - | ||||||||||||||||||
689 | { | - | ||||||||||||||||||
690 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
691 | return d->workingDirectory; | - | ||||||||||||||||||
692 | } | - | ||||||||||||||||||
693 | void QProcess::setWorkingDirectory(const QString &dir) | - | ||||||||||||||||||
694 | { | - | ||||||||||||||||||
695 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
696 | d->workingDirectory = dir; | - | ||||||||||||||||||
697 | } | - | ||||||||||||||||||
698 | Q_PID QProcess::pid() const | - | ||||||||||||||||||
699 | { | - | ||||||||||||||||||
700 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
701 | return d->pid; | - | ||||||||||||||||||
702 | } | - | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | - | |||||||||||||||||||
705 | - | |||||||||||||||||||
706 | - | |||||||||||||||||||
707 | - | |||||||||||||||||||
708 | - | |||||||||||||||||||
709 | - | |||||||||||||||||||
710 | qint64 QProcess::processId() const | - | ||||||||||||||||||
711 | { | - | ||||||||||||||||||
712 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | - | |||||||||||||||||||
715 | - | |||||||||||||||||||
716 | return d->pid; | - | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | - | |||||||||||||||||||
721 | - | |||||||||||||||||||
722 | - | |||||||||||||||||||
723 | - | |||||||||||||||||||
724 | - | |||||||||||||||||||
725 | - | |||||||||||||||||||
726 | bool QProcess::canReadLine() const | - | ||||||||||||||||||
727 | { | - | ||||||||||||||||||
728 | const QProcessPrivate * const d = d_func(); | 1 | ||||||||||||||||||
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError) | ||||||||||||||||||||
? &d->stderrChannel.buffer | ||||||||||||||||||||
: &d->stdoutChannel.buffer;return executed 1 time by 1 test: readBuffer->canReadLine() ||QIODevice::canReadLine();return QIODevice::canReadLine(); Executed by:
executed 1 time by 1 test: return QIODevice::canReadLine(); Executed by:
| ||||||||||||||||||||
729 | } | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | - | |||||||||||||||||||
732 | - | |||||||||||||||||||
733 | - | |||||||||||||||||||
734 | - | |||||||||||||||||||
735 | - | |||||||||||||||||||
736 | void QProcess::close() | - | ||||||||||||||||||
737 | { | - | ||||||||||||||||||
738 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
739 | aboutToClose(); | - | ||||||||||||||||||
740 | while (waitForBytesWritten(-1)
| 0-5 | ||||||||||||||||||
741 | ; never executed: ; | 0 | ||||||||||||||||||
742 | kill(); | - | ||||||||||||||||||
743 | waitForFinished(-1); | - | ||||||||||||||||||
744 | d->setWriteChannelCount(0); | - | ||||||||||||||||||
745 | QIODevice::close(); | - | ||||||||||||||||||
746 | } executed 5 times by 5 tests: end of block Executed by:
| 5 | ||||||||||||||||||
747 | - | |||||||||||||||||||
748 | - | |||||||||||||||||||
749 | - | |||||||||||||||||||
750 | - | |||||||||||||||||||
751 | - | |||||||||||||||||||
752 | - | |||||||||||||||||||
753 | bool QProcess::atEnd() const | - | ||||||||||||||||||
754 | { | - | ||||||||||||||||||
755 | const QProcessPrivate * const d = d_func(); | 61 | ||||||||||||||||||
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError) | ||||||||||||||||||||
? &d->stderrChannel.buffer | ||||||||||||||||||||
: &d->stdoutChannel.buffer;return executed 61 times by 3 tests: QIODevice::atEnd() && (!isOpen() || readBuffer->isEmpty());();return QIODevice::atEnd(); Executed by:
executed 61 times by 3 tests: return QIODevice::atEnd(); Executed by:
| ||||||||||||||||||||
756 | } | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | - | |||||||||||||||||||
759 | - | |||||||||||||||||||
760 | bool QProcess::isSequential() const | - | ||||||||||||||||||
761 | { | - | ||||||||||||||||||
762 | return true; | - | ||||||||||||||||||
763 | } | - | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | - | |||||||||||||||||||
766 | - | |||||||||||||||||||
767 | qint64 QProcess::bytesAvailable() const | - | ||||||||||||||||||
768 | { | - | ||||||||||||||||||
769 | const QProcessPrivate * const d = d_func(); | 872 | ||||||||||||||||||
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError) | ||||||||||||||||||||
? &d->stderrChannel.buffer | ||||||||||||||||||||
: &d->stdoutChannel.buffer;return executed 872 times by 3 tests: readBuffer->size() +QIODevice::bytesAvailable();return QIODevice::bytesAvailable(); Executed by:
executed 872 times by 3 tests: return QIODevice::bytesAvailable(); Executed by:
| ||||||||||||||||||||
770 | } | - | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | - | |||||||||||||||||||
773 | - | |||||||||||||||||||
774 | qint64 QProcess::bytesToWrite() const | - | ||||||||||||||||||
775 | { | - | ||||||||||||||||||
776 | const QProcessPrivate * const d = d_func();qint64 size = d->stdinChannel.buffer.sizeQIODevice::bytesToWrite(); | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | - | |||||||||||||||||||
779 | - | |||||||||||||||||||
780 | return executed 3728 times by 2 tests: size;return size; Executed by:
executed 3728 times by 2 tests: return size; Executed by:
| 3728 | ||||||||||||||||||
781 | } | - | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | - | |||||||||||||||||||
784 | - | |||||||||||||||||||
785 | - | |||||||||||||||||||
786 | - | |||||||||||||||||||
787 | - | |||||||||||||||||||
788 | QProcess::ProcessError QProcess::error() const | - | ||||||||||||||||||
789 | { | - | ||||||||||||||||||
790 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
791 | return d->processError; | - | ||||||||||||||||||
792 | } | - | ||||||||||||||||||
793 | - | |||||||||||||||||||
794 | - | |||||||||||||||||||
795 | - | |||||||||||||||||||
796 | - | |||||||||||||||||||
797 | - | |||||||||||||||||||
798 | - | |||||||||||||||||||
799 | QProcess::ProcessState QProcess::state() const | - | ||||||||||||||||||
800 | { | - | ||||||||||||||||||
801 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
802 | return d->processState; | - | ||||||||||||||||||
803 | } | - | ||||||||||||||||||
804 | void QProcess::setEnvironment(const QStringList &environment) | - | ||||||||||||||||||
805 | { | - | ||||||||||||||||||
806 | setProcessEnvironment(QProcessEnvironmentPrivate::fromList(environment)); | - | ||||||||||||||||||
807 | } | - | ||||||||||||||||||
808 | QStringList QProcess::environment() const | - | ||||||||||||||||||
809 | { | - | ||||||||||||||||||
810 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
811 | return d->environment.toStringList(); | - | ||||||||||||||||||
812 | } | - | ||||||||||||||||||
813 | void QProcess::setProcessEnvironment(const QProcessEnvironment &environment) | - | ||||||||||||||||||
814 | { | - | ||||||||||||||||||
815 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
816 | d->environment = environment; | - | ||||||||||||||||||
817 | } | - | ||||||||||||||||||
818 | QProcessEnvironment QProcess::processEnvironment() const | - | ||||||||||||||||||
819 | { | - | ||||||||||||||||||
820 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
821 | return d->environment; | - | ||||||||||||||||||
822 | } | - | ||||||||||||||||||
823 | bool QProcess::waitForStarted(int msecs) | - | ||||||||||||||||||
824 | { | - | ||||||||||||||||||
825 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
826 | if (d->processState == QProcess::Starting) | - | ||||||||||||||||||
827 | return d->waitForStarted(msecs); | - | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | return d->processState == QProcess::Running; | - | ||||||||||||||||||
830 | } | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | - | |||||||||||||||||||
833 | - | |||||||||||||||||||
834 | bool QProcess::waitForReadyRead(int msecs) | - | ||||||||||||||||||
835 | { | - | ||||||||||||||||||
836 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
837 | - | |||||||||||||||||||
838 | if (d->processState == QProcess::NotRunning
| 1-709 | ||||||||||||||||||
839 | return executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
840 | if (d->processChannelcurrentReadChannel == QProcess::StandardOutput
| 5-681 | ||||||||||||||||||
841 | return executed 5 times by 1 test: false;return false; Executed by:
executed 5 times by 1 test: return false; Executed by:
| 5 | ||||||||||||||||||
842 | if (d->processChannelcurrentReadChannel == QProcess::StandardError
| 5-676 | ||||||||||||||||||
843 | return executed 5 times by 1 test: false;return false; Executed by:
executed 5 times by 1 test: return false; Executed by:
| 5 | ||||||||||||||||||
844 | return executed 699 times by 9 tests: d->waitForReadyRead(msecs);return d->waitForReadyRead(msecs); Executed by:
executed 699 times by 9 tests: return d->waitForReadyRead(msecs); Executed by:
| 699 | ||||||||||||||||||
845 | } | - | ||||||||||||||||||
846 | - | |||||||||||||||||||
847 | - | |||||||||||||||||||
848 | - | |||||||||||||||||||
849 | bool QProcess::waitForBytesWritten(int msecs) | - | ||||||||||||||||||
850 | { | - | ||||||||||||||||||
851 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
852 | if (d->processState == QProcess::NotRunning) | - | ||||||||||||||||||
853 | return false; | - | ||||||||||||||||||
854 | if (d->processState == QProcess::Starting) { | - | ||||||||||||||||||
855 | QElapsedTimer stopWatch; | - | ||||||||||||||||||
856 | stopWatch.start(); | - | ||||||||||||||||||
857 | bool started = waitForStarted(msecs); | - | ||||||||||||||||||
858 | if (!started) | - | ||||||||||||||||||
859 | return false; | - | ||||||||||||||||||
860 | msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed()); | - | ||||||||||||||||||
861 | } | - | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | return d->waitForBytesWritten(msecs); | - | ||||||||||||||||||
864 | } | - | ||||||||||||||||||
865 | bool QProcess::waitForFinished(int msecs) | - | ||||||||||||||||||
866 | { | - | ||||||||||||||||||
867 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
868 | if (d->processState == QProcess::NotRunning) | - | ||||||||||||||||||
869 | return false; | - | ||||||||||||||||||
870 | if (d->processState == QProcess::Starting) { | - | ||||||||||||||||||
871 | QElapsedTimer stopWatch; | - | ||||||||||||||||||
872 | stopWatch.start(); | - | ||||||||||||||||||
873 | bool started = waitForStarted(msecs); | - | ||||||||||||||||||
874 | if (!started) | - | ||||||||||||||||||
875 | return false; | - | ||||||||||||||||||
876 | msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed()); | - | ||||||||||||||||||
877 | } | - | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | return d->waitForFinished(msecs); | - | ||||||||||||||||||
880 | } | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | - | |||||||||||||||||||
883 | - | |||||||||||||||||||
884 | - | |||||||||||||||||||
885 | - | |||||||||||||||||||
886 | - | |||||||||||||||||||
887 | void QProcess::setProcessState(ProcessState state) | - | ||||||||||||||||||
888 | { | - | ||||||||||||||||||
889 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
890 | if (d->processState == state) | - | ||||||||||||||||||
891 | return; | - | ||||||||||||||||||
892 | d->processState = state; | - | ||||||||||||||||||
893 | stateChanged(state, QPrivateSignal()); | - | ||||||||||||||||||
894 | } | - | ||||||||||||||||||
895 | void QProcess::setupChildProcess() | - | ||||||||||||||||||
896 | { | - | ||||||||||||||||||
897 | } | - | ||||||||||||||||||
898 | - | |||||||||||||||||||
899 | - | |||||||||||||||||||
900 | - | |||||||||||||||||||
901 | qint64 QProcess::readData(char *data, qint64 maxlen) | - | ||||||||||||||||||
902 | { | - | ||||||||||||||||||
903 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
904 | if (!maxlen) | - | ||||||||||||||||||
return 0; | ||||||||||||||||||||
QRingBuffer *readBuffer =(d->processChannel == QProcess::StandardErrorvoid)? &d->stderrChannel.buffer | ||||||||||||||||||||
: &d->stdoutChannel.buffer;data;; | ||||||||||||||||||||
905 | if ((!
| 258-4081 | ||||||||||||||||||
int c = readBuffer->getChar();
| ||||||||||||||||||||
if (c == -1) {
| ||||||||||||||||||||
return -1;
| ||||||||||||||||||||
}
| ||||||||||||||||||||
*data = (char
| ||||||||||||||||||||
906 | c;return executed 258 times by 6 tests: 1;return 0; Executed by:
executed 258 times by 6 tests: return 0; Executed by:
| 258 | ||||||||||||||||||
} executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
qint64 bytesToRead = qMin(readBuffer->size(), maxlen); executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
qint64 readSoFar = executed 258 times by 6 tests: return 0; Executed by:
executed 258 times by 6 tests: 0;return 0; Executed by:
executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
while (readSoFar < bytesToRead) { executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
const char *ptr = readBuffer->readPointer(); executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
readBuffer->nextDataBlockSize()); executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
readSoFar += bytesToReadFromThisBlock executed 258 times by 6 tests: return 0; Executed by:
executed 258 times by 6 tests: ;return 0; Executed by:
executed 258 times by 6 tests: return 0; Executed by:
| ||||||||||||||||||||
907 | readBuffer->free(bytesToReadFromThisBlock); | 598-3483 | ||||||||||||||||||
}if (!readSoFar &&(d->processState == QProcess::NotRunning
| ||||||||||||||||||||
908 | return executed 3483 times by 16 tests: -1;return -1; Executed by:
executed 3483 times by 16 tests: return -1; Executed by:
| 3483 | ||||||||||||||||||
909 | return executed 598 times by 5 tests: readSoFar0;return 0; Executed by:
executed 598 times by 5 tests: return 0; Executed by:
| 598 | ||||||||||||||||||
910 | } | - | ||||||||||||||||||
911 | - | |||||||||||||||||||
912 | - | |||||||||||||||||||
913 | - | |||||||||||||||||||
914 | qint64 QProcess::writeData(const char *data, qint64 len) | - | ||||||||||||||||||
915 | { | - | ||||||||||||||||||
916 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
917 | if (d->stdinChannel.closed
| 0-1167 | ||||||||||||||||||
918 | - | |||||||||||||||||||
919 | - | |||||||||||||||||||
920 | - | |||||||||||||||||||
921 | - | |||||||||||||||||||
922 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
} never executed: return 0; | ||||||||||||||||||||
if (len == 1) { never executed: return 0; | ||||||||||||||||||||
d->stdinChannel.buffer.putChar(*data); never executed: return 0; | ||||||||||||||||||||
if (d->stdinChannel.notifier) never executed: return 0; | ||||||||||||||||||||
d->stdinChannel.notifier->setEnabled(true); never executed: return 0; | ||||||||||||||||||||
return 1 never executed: return 0; never executed: ;return 0; never executed: return 0; | ||||||||||||||||||||
923 | } | - | ||||||||||||||||||
924 | char *dest =d->stdinChannel.bufferwriteBuffer.reserve(len); | - | ||||||||||||||||||
memcpyappend(dest,data, len); | ||||||||||||||||||||
925 | - | |||||||||||||||||||
926 | - | |||||||||||||||||||
927 | - | |||||||||||||||||||
928 | - | |||||||||||||||||||
929 | if (d->stdinChannel.notifier
| 0-1167 | ||||||||||||||||||
930 | d->stdinChannel.notifier->setEnabled(true); executed 1167 times by 7 tests: d->stdinChannel.notifier->setEnabled(true); Executed by:
| 1167 | ||||||||||||||||||
931 | - | |||||||||||||||||||
932 | - | |||||||||||||||||||
933 | - | |||||||||||||||||||
934 | - | |||||||||||||||||||
935 | - | |||||||||||||||||||
936 | return executed 1167 times by 7 tests: len;return len; Executed by:
executed 1167 times by 7 tests: return len; Executed by:
| 1167 | ||||||||||||||||||
937 | } | - | ||||||||||||||||||
938 | QByteArray QProcess::readAllStandardOutput() | - | ||||||||||||||||||
939 | { | - | ||||||||||||||||||
940 | ProcessChannel tmp = readChannel(); | - | ||||||||||||||||||
941 | setReadChannel(StandardOutput); | - | ||||||||||||||||||
942 | QByteArray data = readAll(); | - | ||||||||||||||||||
943 | setReadChannel(tmp); | - | ||||||||||||||||||
944 | return data; | - | ||||||||||||||||||
945 | } | - | ||||||||||||||||||
946 | QByteArray QProcess::readAllStandardError() | - | ||||||||||||||||||
947 | { | - | ||||||||||||||||||
948 | ProcessChannel tmp = readChannel(); | - | ||||||||||||||||||
949 | setReadChannel(StandardError); | - | ||||||||||||||||||
950 | QByteArray data = readAll(); | - | ||||||||||||||||||
951 | setReadChannel(tmp); | - | ||||||||||||||||||
952 | return data; | - | ||||||||||||||||||
953 | } | - | ||||||||||||||||||
954 | void QProcess::start(const QString &program, const QStringList &arguments, OpenMode mode) | - | ||||||||||||||||||
955 | { | - | ||||||||||||||||||
956 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
957 | if (d->processState != NotRunning) { | - | ||||||||||||||||||
958 | QMessageLogger(__FILE__, 20892083, __PRETTY_FUNCTION__).warning("QProcess::start: Process is already running"); | - | ||||||||||||||||||
959 | return; | - | ||||||||||||||||||
960 | } | - | ||||||||||||||||||
961 | if (program.isEmpty()) { | - | ||||||||||||||||||
962 | d->setErrorAndEmit(QProcess::FailedToStart, tr("No program defined")); | - | ||||||||||||||||||
963 | return; | - | ||||||||||||||||||
964 | } | - | ||||||||||||||||||
965 | - | |||||||||||||||||||
966 | d->program = program; | - | ||||||||||||||||||
967 | d->arguments = arguments; | - | ||||||||||||||||||
968 | - | |||||||||||||||||||
969 | d->start(mode); | - | ||||||||||||||||||
970 | } | - | ||||||||||||||||||
971 | void QProcess::start(OpenMode mode) | - | ||||||||||||||||||
972 | { | - | ||||||||||||||||||
973 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
974 | if (d->processState != NotRunning) { | - | ||||||||||||||||||
975 | QMessageLogger(__FILE__, 21162110, __PRETTY_FUNCTION__).warning("QProcess::start: Process is already running"); | - | ||||||||||||||||||
976 | return; | - | ||||||||||||||||||
977 | } | - | ||||||||||||||||||
978 | if (d->program.isEmpty()) { | - | ||||||||||||||||||
979 | d->setErrorAndEmit(QProcess::FailedToStart, tr("No program defined")); | - | ||||||||||||||||||
980 | return; | - | ||||||||||||||||||
981 | } | - | ||||||||||||||||||
982 | - | |||||||||||||||||||
983 | d->start(mode); | - | ||||||||||||||||||
984 | } | - | ||||||||||||||||||
985 | bool QProcess::open(OpenMode mode) | - | ||||||||||||||||||
986 | { | - | ||||||||||||||||||
987 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
988 | if (d->processState != NotRunning) { | - | ||||||||||||||||||
989 | QMessageLogger(__FILE__, 21402134, __PRETTY_FUNCTION__).warning("QProcess::start: Process is already running"); | - | ||||||||||||||||||
990 | return false; | - | ||||||||||||||||||
991 | } | - | ||||||||||||||||||
992 | if (d->program.isEmpty()) { | - | ||||||||||||||||||
993 | QMessageLogger(__FILE__, 21442138, __PRETTY_FUNCTION__).warning("QProcess::start: program not set"); | - | ||||||||||||||||||
994 | return false; | - | ||||||||||||||||||
995 | } | - | ||||||||||||||||||
996 | - | |||||||||||||||||||
997 | d->start(mode); | - | ||||||||||||||||||
998 | return true; | - | ||||||||||||||||||
999 | } | - | ||||||||||||||||||
1000 | - | |||||||||||||||||||
1001 | void QProcessPrivate::start(QIODevice::OpenMode mode) | - | ||||||||||||||||||
1002 | { | - | ||||||||||||||||||
1003 | QProcess * const q = q_func(); | - | ||||||||||||||||||
stdinChannel.buffer.clear(); | ||||||||||||||||||||
stdoutChannel.buffer.clear(); | ||||||||||||||||||||
stderrChannel.buffer.clear(); | ||||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | if (stdinChannel.type != QProcessPrivate::Channel::Normal
| 5-3018 | ||||||||||||||||||
1009 | mode &= ~QIODevice::WriteOnly; executed 5 times by 1 test: mode &= ~QIODevice::WriteOnly; Executed by:
| 5 | ||||||||||||||||||
1010 | if (stdoutChannel.type != QProcessPrivate::Channel::Normal
| 9-3014 | ||||||||||||||||||
1011 | (stderrChannel.type != QProcessPrivate::Channel::Normal
| 0-9 | ||||||||||||||||||
1012 | processChannelMode == QProcess::MergedChannels
| 3-6 | ||||||||||||||||||
1013 | mode &= ~QIODevice::ReadOnly; executed 3 times by 1 test: mode &= ~QIODevice::ReadOnly; Executed by:
| 3 | ||||||||||||||||||
1014 | if (mode == 0
| 0-3023 | ||||||||||||||||||
1015 | mode = QIODevice::Unbuffered; never executed: mode = QIODevice::Unbuffered; | 0 | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | if ((
| 4-3019 | ||||||||||||||||||
1018 | if (stdoutChannel.type == QProcessPrivate::Channel::Normal
| 1-3 | ||||||||||||||||||
1019 | q->setStandardOutputFile(q->nullDevice()); executed 1 time by 1 test: q->setStandardOutputFile(q->nullDevice()); Executed by:
| 1 | ||||||||||||||||||
1020 | if (stderrChannel.type == QProcessPrivate::Channel::Normal
| 0-4 | ||||||||||||||||||
1021 | && processChannelMode != QProcess::MergedChannels
| 1-3 | ||||||||||||||||||
1022 | q->setStandardErrorFile(q->nullDevice()); executed 1 time by 1 test: q->setStandardErrorFile(q->nullDevice()); Executed by:
| 1 | ||||||||||||||||||
1023 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | - | |||||||||||||||||||
1026 | q->QIODevice::open(mode); | - | ||||||||||||||||||
1027 | - | |||||||||||||||||||
1028 | if (q->isReadable()
| 4-3019 | ||||||||||||||||||
1029 | setReadChannelCount(2 executed 3004 times by 38 tests: setReadChannelCount(2); Executed by:
executed 3004 times by 38 tests: );setReadChannelCount(2); Executed by:
executed 3004 times by 38 tests: setReadChannelCount(2); Executed by:
| 3004 | ||||||||||||||||||
1030 | - | |||||||||||||||||||
1031 | stdinChannel.closed = false; | - | ||||||||||||||||||
1032 | stdoutChannel.closed = false; | - | ||||||||||||||||||
1033 | stderrChannel.closed = false; | - | ||||||||||||||||||
1034 | - | |||||||||||||||||||
1035 | exitCode = 0; | - | ||||||||||||||||||
1036 | exitStatus = QProcess::NormalExit; | - | ||||||||||||||||||
1037 | processError = QProcess::UnknownError; | - | ||||||||||||||||||
1038 | errorString.clear(); | - | ||||||||||||||||||
1039 | startProcess(); | - | ||||||||||||||||||
1040 | } executed 3023 times by 39 tests: end of block Executed by:
| 3023 | ||||||||||||||||||
1041 | - | |||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | static QStringList parseCombinedArgString(const QString &program) | - | ||||||||||||||||||
1044 | { | - | ||||||||||||||||||
1045 | QStringList args; | - | ||||||||||||||||||
1046 | QString tmp; | - | ||||||||||||||||||
1047 | int quoteCount = 0; | - | ||||||||||||||||||
1048 | bool inQuote = false; | - | ||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | - | |||||||||||||||||||
1052 | - | |||||||||||||||||||
1053 | for (int i = 0; i < program.size(); ++i) { | - | ||||||||||||||||||
1054 | if (program.at(i) == QLatin1Char('"')) { | - | ||||||||||||||||||
1055 | ++quoteCount; | - | ||||||||||||||||||
1056 | if (quoteCount == 3) { | - | ||||||||||||||||||
1057 | - | |||||||||||||||||||
1058 | quoteCount = 0; | - | ||||||||||||||||||
1059 | tmp += program.at(i); | - | ||||||||||||||||||
1060 | } | - | ||||||||||||||||||
1061 | continue; | - | ||||||||||||||||||
1062 | } | - | ||||||||||||||||||
1063 | if (quoteCount) { | - | ||||||||||||||||||
1064 | if (quoteCount == 1) | - | ||||||||||||||||||
1065 | inQuote = !inQuote; | - | ||||||||||||||||||
1066 | quoteCount = 0; | - | ||||||||||||||||||
1067 | } | - | ||||||||||||||||||
1068 | if (!inQuote && program.at(i).isSpace()) { | - | ||||||||||||||||||
1069 | if (!tmp.isEmpty()) { | - | ||||||||||||||||||
1070 | args += tmp; | - | ||||||||||||||||||
1071 | tmp.clear(); | - | ||||||||||||||||||
1072 | } | - | ||||||||||||||||||
1073 | } else { | - | ||||||||||||||||||
1074 | tmp += program.at(i); | - | ||||||||||||||||||
1075 | } | - | ||||||||||||||||||
1076 | } | - | ||||||||||||||||||
1077 | if (!tmp.isEmpty()) | - | ||||||||||||||||||
1078 | args += tmp; | - | ||||||||||||||||||
1079 | - | |||||||||||||||||||
1080 | return args; | - | ||||||||||||||||||
1081 | } | - | ||||||||||||||||||
1082 | void QProcess::start(const QString &command, OpenMode mode) | - | ||||||||||||||||||
1083 | { | - | ||||||||||||||||||
1084 | QStringList args = parseCombinedArgString(command); | - | ||||||||||||||||||
1085 | if (args.isEmpty()
| 4-1318 | ||||||||||||||||||
1086 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1087 | d->setErrorAndEmit(QProcess::FailedToStart, tr("No program defined")); | - | ||||||||||||||||||
1088 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
1089 | } | - | ||||||||||||||||||
1090 | - | |||||||||||||||||||
1091 | const QString prog = args.first(); | - | ||||||||||||||||||
args.removeFirsttakeFirst(); | ||||||||||||||||||||
1092 | - | |||||||||||||||||||
1093 | start(prog, args, mode); | - | ||||||||||||||||||
1094 | } executed 1318 times by 16 tests: end of block Executed by:
| 1318 | ||||||||||||||||||
1095 | QString QProcess::program() const | - | ||||||||||||||||||
1096 | { | - | ||||||||||||||||||
1097 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1098 | return d->program; | - | ||||||||||||||||||
1099 | } | - | ||||||||||||||||||
1100 | void QProcess::setProgram(const QString &program) | - | ||||||||||||||||||
1101 | { | - | ||||||||||||||||||
1102 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1103 | if (d->processState != NotRunning) { | - | ||||||||||||||||||
1104 | QMessageLogger(__FILE__, 23152307, __PRETTY_FUNCTION__).warning("QProcess::setProgram: Process is already running"); | - | ||||||||||||||||||
1105 | return; | - | ||||||||||||||||||
1106 | } | - | ||||||||||||||||||
1107 | d->program = program; | - | ||||||||||||||||||
1108 | } | - | ||||||||||||||||||
1109 | QStringList QProcess::arguments() const | - | ||||||||||||||||||
1110 | { | - | ||||||||||||||||||
1111 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1112 | return d->arguments; | - | ||||||||||||||||||
1113 | } | - | ||||||||||||||||||
1114 | void QProcess::setArguments(const QStringList &arguments) | - | ||||||||||||||||||
1115 | { | - | ||||||||||||||||||
1116 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1117 | if (d->processState != NotRunning) { | - | ||||||||||||||||||
1118 | QMessageLogger(__FILE__, 23462338, __PRETTY_FUNCTION__).warning("QProcess::setProgram: Process is already running"); | - | ||||||||||||||||||
1119 | return; | - | ||||||||||||||||||
1120 | } | - | ||||||||||||||||||
1121 | d->arguments = arguments; | - | ||||||||||||||||||
1122 | } | - | ||||||||||||||||||
1123 | void QProcess::terminate() | - | ||||||||||||||||||
1124 | { | - | ||||||||||||||||||
1125 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1126 | d->terminateProcess(); | - | ||||||||||||||||||
1127 | } | - | ||||||||||||||||||
1128 | void QProcess::kill() | - | ||||||||||||||||||
1129 | { | - | ||||||||||||||||||
1130 | QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1131 | d->killProcess(); | - | ||||||||||||||||||
1132 | } | - | ||||||||||||||||||
1133 | - | |||||||||||||||||||
1134 | - | |||||||||||||||||||
1135 | - | |||||||||||||||||||
1136 | - | |||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | - | |||||||||||||||||||
1139 | int QProcess::exitCode() const | - | ||||||||||||||||||
1140 | { | - | ||||||||||||||||||
1141 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1142 | return d->exitCode; | - | ||||||||||||||||||
1143 | } | - | ||||||||||||||||||
1144 | QProcess::ExitStatus QProcess::exitStatus() const | - | ||||||||||||||||||
1145 | { | - | ||||||||||||||||||
1146 | const QProcessPrivate * const d = d_func(); | - | ||||||||||||||||||
1147 | return d->exitStatus; | - | ||||||||||||||||||
1148 | } | - | ||||||||||||||||||
1149 | int QProcess::execute(const QString &program, const QStringList &arguments) | - | ||||||||||||||||||
1150 | { | - | ||||||||||||||||||
1151 | QProcess process; | - | ||||||||||||||||||
1152 | process.setReadChannelMode(ForwardedChannels); | - | ||||||||||||||||||
1153 | process.start(program, arguments); | - | ||||||||||||||||||
1154 | if (!process.waitForFinished(-1) || process.error() == FailedToStart) | - | ||||||||||||||||||
1155 | return -2; | - | ||||||||||||||||||
1156 | return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1; | - | ||||||||||||||||||
1157 | } | - | ||||||||||||||||||
1158 | int QProcess::execute(const QString &command) | - | ||||||||||||||||||
1159 | { | - | ||||||||||||||||||
1160 | QProcess process; | - | ||||||||||||||||||
1161 | process.setReadChannelMode(ForwardedChannels); | - | ||||||||||||||||||
1162 | process.start(command); | - | ||||||||||||||||||
1163 | if (!process.waitForFinished(-1) || process.error() == FailedToStart) | - | ||||||||||||||||||
1164 | return -2; | - | ||||||||||||||||||
1165 | return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1; | - | ||||||||||||||||||
1166 | } | - | ||||||||||||||||||
1167 | bool QProcess::startDetached(const QString &program, | - | ||||||||||||||||||
1168 | const QStringList &arguments, | - | ||||||||||||||||||
1169 | const QString &workingDirectory, | - | ||||||||||||||||||
1170 | qint64 *pid) | - | ||||||||||||||||||
1171 | { | - | ||||||||||||||||||
1172 | return QProcessPrivate::startDetached(program, | - | ||||||||||||||||||
1173 | arguments, | - | ||||||||||||||||||
1174 | workingDirectory, | - | ||||||||||||||||||
1175 | pid); | - | ||||||||||||||||||
1176 | } | - | ||||||||||||||||||
1177 | - | |||||||||||||||||||
1178 | - | |||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | - | |||||||||||||||||||
1181 | bool QProcess::startDetached(const QString &program, | - | ||||||||||||||||||
1182 | const QStringList &arguments) | - | ||||||||||||||||||
1183 | { | - | ||||||||||||||||||
1184 | return QProcessPrivate::startDetached(program, arguments); | - | ||||||||||||||||||
1185 | } | - | ||||||||||||||||||
1186 | bool QProcess::startDetached(const QString &command) | - | ||||||||||||||||||
1187 | { | - | ||||||||||||||||||
1188 | QStringList args = parseCombinedArgString(command); | - | ||||||||||||||||||
1189 | if (args.isEmpty()
| 2-3 | ||||||||||||||||||
1190 | return executed 3 times by 1 test: false;return false; Executed by:
executed 3 times by 1 test: return false; Executed by:
| 3 | ||||||||||||||||||
1191 | - | |||||||||||||||||||
1192 | const QString prog = args.first(); | - | ||||||||||||||||||
args.removeFirsttakeFirst(); | ||||||||||||||||||||
1193 | - | |||||||||||||||||||
1194 | return executed 2 times by 1 test: QProcessPrivate::startDetached(prog, args);return QProcessPrivate::startDetached(prog, args); Executed by:
executed 2 times by 1 test: return QProcessPrivate::startDetached(prog, args); Executed by:
| 2 | ||||||||||||||||||
1195 | } | - | ||||||||||||||||||
1196 | - | |||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | - | |||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | - | |||||||||||||||||||
1202 | - | |||||||||||||||||||
1203 | - | |||||||||||||||||||
1204 | - | |||||||||||||||||||
1205 | extern char **environ; | - | ||||||||||||||||||
1206 | - | |||||||||||||||||||
1207 | - | |||||||||||||||||||
1208 | QStringList QProcess::systemEnvironment() | - | ||||||||||||||||||
1209 | { | - | ||||||||||||||||||
1210 | QStringList tmp; | - | ||||||||||||||||||
1211 | char *entry = 0; | - | ||||||||||||||||||
1212 | int count = 0; | - | ||||||||||||||||||
1213 | while ((entry = environ[count++])) | - | ||||||||||||||||||
1214 | tmp << QString::fromLocal8Bit(entry); | - | ||||||||||||||||||
1215 | return tmp; | - | ||||||||||||||||||
1216 | } | - | ||||||||||||||||||
1217 | QString QProcess::nullDevice() | - | ||||||||||||||||||
1218 | { | - | ||||||||||||||||||
1219 | - | |||||||||||||||||||
1220 | - | |||||||||||||||||||
1221 | - | |||||||||||||||||||
1222 | return ([]() -> QString { enum { Size = sizeof(u"" "/dev/null")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/dev/null" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); | - | ||||||||||||||||||
1223 | - | |||||||||||||||||||
1224 | } | - | ||||||||||||||||||
1225 | - | |||||||||||||||||||
1226 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |