File: qprocess.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (351 lines) | stat: -rw-r--r-- 43,575 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QProcess Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QProcess Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QProcess class is used to start external programs and to communicate with them. <a href="#details">More...</a></p>
<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qprocess.html#ExitStatus-enum">ExitStatus</a></b> { NormalExit, CrashExit }</li><li><div class="fn" />enum <b><a href="qprocess.html#ProcessChannel-enum">ProcessChannel</a></b> { StandardOutput, StandardError }</li><li><div class="fn" />enum <b><a href="qprocess.html#ProcessChannelMode-enum">ProcessChannelMode</a></b> { SeparateChannels, MergedChannels, ForwardedChannels }</li><li><div class="fn" />enum <b><a href="qprocess.html#ProcessError-enum">ProcessError</a></b> { FailedToStart, Crashed, Timedout, ReadError, WriteError, UnknownError }</li><li><div class="fn" />enum <b><a href="qprocess.html#ProcessState-enum">ProcessState</a></b> { NotRunning, Starting, Running }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qprocess.html#QProcess">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />bool <b><a href="qprocess.html#atEnd">atEnd</a></b> (<i>self</i>)</li><li><div class="fn" />long <b><a href="qprocess.html#bytesAvailable">bytesAvailable</a></b> (<i>self</i>)</li><li><div class="fn" />long <b><a href="qprocess.html#bytesToWrite">bytesToWrite</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qprocess.html#canReadLine">canReadLine</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qprocess.html#close">close</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qprocess.html#closeReadChannel">closeReadChannel</a></b> (<i>self</i>, ProcessChannel&#160;<i>channel</i>)</li><li><div class="fn" /><b><a href="qprocess.html#closeWriteChannel">closeWriteChannel</a></b> (<i>self</i>)</li><li><div class="fn" />QStringList <b><a href="qprocess.html#environment">environment</a></b> (<i>self</i>)</li><li><div class="fn" />ProcessError <b><a href="qprocess.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qprocess.html#exitCode">exitCode</a></b> (<i>self</i>)</li><li><div class="fn" />ExitStatus <b><a href="qprocess.html#exitStatus">exitStatus</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qprocess.html#isSequential">isSequential</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qprocess.html#kill">kill</a></b> (<i>self</i>)</li><li><div class="fn" />long <b><a href="qprocess.html#pid">pid</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qprocess.html#readAllStandardError">readAllStandardError</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qprocess.html#readAllStandardOutput">readAllStandardOutput</a></b> (<i>self</i>)</li><li><div class="fn" />ProcessChannel <b><a href="qprocess.html#readChannel">readChannel</a></b> (<i>self</i>)</li><li><div class="fn" />ProcessChannelMode <b><a href="qprocess.html#readChannelMode">readChannelMode</a></b> (<i>self</i>)</li><li><div class="fn" />object <b><a href="qprocess.html#readData">readData</a></b> (<i>self</i>, long&#160;<i>maxlen</i>)</li><li><div class="fn" /><b><a href="qprocess.html#setEnvironment">setEnvironment</a></b> (<i>self</i>, QStringList&#160;<i>environment</i>)</li><li><div class="fn" /><b><a href="qprocess.html#setProcessState">setProcessState</a></b> (<i>self</i>, ProcessState&#160;<i>state</i>)</li><li><div class="fn" /><b><a href="qprocess.html#setReadChannel">setReadChannel</a></b> (<i>self</i>, ProcessChannel&#160;<i>channel</i>)</li><li><div class="fn" /><b><a href="qprocess.html#setReadChannelMode">setReadChannelMode</a></b> (<i>self</i>, ProcessChannelMode&#160;<i>mode</i>)</li><li><div class="fn" /><b><a href="qprocess.html#setupChildProcess">setupChildProcess</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qprocess.html#setWorkingDirectory">setWorkingDirectory</a></b> (<i>self</i>, QString&#160;<i>dir</i>)</li><li><div class="fn" /><b><a href="qprocess.html#start">start</a></b> (<i>self</i>, QString&#160;<i>program</i>, QStringList&#160;<i>arguments</i>, QIODevice.OpenMode&#160;<i>mode</i>&#160;=&#160;QIODevice.ReadWrite)</li><li><div class="fn" /><b><a href="qprocess.html#start-2">start</a></b> (<i>self</i>, QString&#160;<i>program</i>, QIODevice.OpenMode&#160;<i>mode</i>&#160;=&#160;QIODevice.ReadWrite)</li><li><div class="fn" />ProcessState <b><a href="qprocess.html#state">state</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qprocess.html#terminate">terminate</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qprocess.html#waitForBytesWritten">waitForBytesWritten</a></b> (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</li><li><div class="fn" />bool <b><a href="qprocess.html#waitForFinished">waitForFinished</a></b> (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</li><li><div class="fn" />bool <b><a href="qprocess.html#waitForReadyRead">waitForReadyRead</a></b> (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</li><li><div class="fn" />bool <b><a href="qprocess.html#waitForStarted">waitForStarted</a></b> (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</li><li><div class="fn" />QString <b><a href="qprocess.html#workingDirectory">workingDirectory</a></b> (<i>self</i>)</li><li><div class="fn" />long <b><a href="qprocess.html#writeData">writeData</a></b> (<i>self</i>, str&#160;<i>data</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />int <b><a href="qprocess.html#execute">execute</a></b> (QString&#160;<i>program</i>, QStringList&#160;<i>arguments</i>)</li><li><div class="fn" />int <b><a href="qprocess.html#execute-2">execute</a></b> (QString&#160;<i>program</i>)</li><li><div class="fn" />bool <b><a href="qprocess.html#startDetached">startDetached</a></b> (QString&#160;<i>program</i>, QStringList&#160;<i>arguments</i>)</li><li><div class="fn" />bool <b><a href="qprocess.html#startDetached-2">startDetached</a></b> (QString&#160;<i>program</i>)</li><li><div class="fn" />QStringList <b><a href="qprocess.html#systemEnvironment">systemEnvironment</a></b> ()</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qprocess.html#error-2">error</a></b> (QProcess::ProcessError)</li><li><div class="fn" />void <b><a href="qprocess.html#finished">finished</a></b> (int)</li><li><div class="fn" />void <b><a href="qprocess.html#finished-2">finished</a></b> (int,QProcess::ExitStatus)</li><li><div class="fn" />void <b><a href="qprocess.html#readyReadStandardError">readyReadStandardError</a></b> ()</li><li><div class="fn" />void <b><a href="qprocess.html#readyReadStandardOutput">readyReadStandardOutput</a></b> ()</li><li><div class="fn" />void <b><a href="qprocess.html#started">started</a></b> ()</li><li><div class="fn" />void <b><a href="qprocess.html#stateChanged">stateChanged</a></b> (QProcess::ProcessState)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QProcess class is used to start external programs and to communicate with them.</p>
<p>To start a process, pass the name and command line arguments of the program you want to run as arguments to <a href="qprocess.html#start">start</a>(). For example:</p>
<pre>
        QObject *parent;
        ...
        QString program = "./path/to/Qt/examples/widgets/analogclock";
        QStringList arguments;
        arguments &lt;&lt; "-style" &lt;&lt; "motif";

        QProcess *myProcess = new QProcess(parent);
        myProcess-&gt;start(program, arguments);
</pre>
<p>QProcess then enters the <a href="qprocess.html#ProcessState-enum">Starting</a> state, and when the program has started, QProcess enters the <a href="qprocess.html#ProcessState-enum">Running</a> state and emits <a href="qprocess.html#started">started</a>().</p>
<p>QProcess allows you to treat a process as a sequential I/O device. You can write to and read from the process just as you would access a network connection using <a href="qtcpsocket.html">QTcpSocket</a>. You can then write to the process's standard input by calling <a href="qiodevice.html#write">write</a>(), and read the standard output by calling <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), and <a href="qiodevice.html#getChar">getChar</a>(). Because it inherits <a href="qiodevice.html">QIODevice</a>, QProcess can also be used as an input source for <a href="qxmlreader.html">QXmlReader</a>, or for generating data to be uploaded using <a href="qftp.html">QFtp</a>.</p>
<p>When the process exits, QProcess reenters the <a href="qprocess.html#ProcessState-enum">NotRunning</a> state (the initial state), and emits <a href="qprocess.html#finished">finished</a>().</p>
<p>The <a href="qprocess.html#finished">finished</a>() signal provides the exit code and exit status of the process as arguments, and you can also call <a href="qprocess.html#exitCode">exitCode</a>() to obtain the exit code of the last process that finished, and <a href="qprocess.html#exitStatus">exitStatus</a>() to obtain its exit status. If an error occurs at any point in time, QProcess will emit the <a href="qprocess.html#error">error</a>() signal. You can also call <a href="qprocess.html#error">error</a>() to find the type of error that occurred last, and <a href="qprocess.html#state">state</a>() to find the current process state.</p>
<p>Processes have two predefined output channels: The standard output channel (<tt>stdout</tt>) supplies regular console output, and the standard error channel (<tt>stderr</tt>) usually supplies the errors that are printed by the process. These channels represent two separate streams of data. You can toggle between them by calling <a href="qprocess.html#setReadChannel">setReadChannel</a>(). QProcess emits <a href="qiodevice.html#readyRead">readyRead</a>() when data is available on the current read channel. It also emits <a href="qprocess.html#readyReadStandardOutput">readyReadStandardOutput</a>() when new standard output data is available, and when new standard error data is available, <a href="qprocess.html#readyReadStandardError">readyReadStandardError</a>() is emitted. Instead of calling <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), or <a href="qiodevice.html#getChar">getChar</a>(), you can explicitly read all data from either of the two channels by calling <a href="qprocess.html#readAllStandardOutput">readAllStandardOutput</a>() or <a href="qprocess.html#readAllStandardError">readAllStandardError</a>().</p>
<p>The terminology for the channels can be misleading. Be aware that the process's output channels correspond to QProcess's <i>read</i> channels, whereas the process's input channels correspond to QProcess's <i>write</i> channels. This is because what we read using QProcess is the process's output, and what we write becomes the process's input.</p>
<p>QProcess can merge the two output channels, so that standard output and standard error data from the running process both use the standard output channel. Call <a href="qprocess.html#setReadChannelMode">setReadChannelMode</a>() with <a href="qprocess.html#ProcessChannelMode-enum">MergedChannels</a> before starting the process to activative this feature. You also have the option of forwarding the output of the running process to the calling, main process, by passing <a href="qprocess.html#ProcessChannelMode-enum">ForwardedChannels</a> as the argument.</p>
<p>Certain processes need special environment settings in order to operate. You can set environment variables for your process by calling <a href="qprocess.html#setEnvironment">setEnvironment</a>(). To set a working directory, call <a href="qprocess.html#setWorkingDirectory">setWorkingDirectory</a>(). By default, processes are run in the current working directory of the calling process.</p>
<p>QProcess provides a set of functions which allow it to be used without an event loop, by suspending the calling thread until certain signals are emitted:</p>
<ul>
<li><a href="qprocess.html#waitForStarted">waitForStarted</a>() blocks until the process has started.</li>
<li><a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>() blocks until new data is available for reading on the current read channel.</li>
<li><a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>() blocks until one payload of data has been written to the process.</li>
<li><a href="qprocess.html#waitForFinished">waitForFinished</a>() blocks until the process has finished.</li>
</ul>
<p>Calling these functions from the main thread (the thread that calls <a href="qapplication.html#exec">QApplication.exec</a>()) may cause your user interface to freeze.</p>
<p>The following example runs <tt>gzip</tt> to compress the string "Qt rocks!", without an event loop:</p>
<pre>
        QProcess gzip;
        gzip.start("gzip", QStringList() &lt;&lt; "-c");
        if (!gzip.waitForStarted())
            return false;

        gzip.write("Qt rocks!");
        gzip.closeWriteChannel();

        if (!gzip.waitForFinished())
            return false;

        QByteArray result = gzip.readAll();
</pre>
<p>See also <a href="qbuffer.html">QBuffer</a>, <a href="qfile.html">QFile</a>, and <a href="qtcpsocket.html">QTcpSocket</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ExitStatus-enum" />QProcess.ExitStatus</h3><p>This enum describes the different exit statuses of <a href="qprocess.html">QProcess</a>.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QProcess.NormalExit</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">The process exited normally.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.CrashExit</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">The process crashed.</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qprocess.html#exitStatus">exitStatus</a>().</p>
<h3 class="fn"><a name="ProcessChannel-enum" />QProcess.ProcessChannel</h3><p>This enum describes the process channels used by the running process. Pass one of these values to <a href="qprocess.html#setReadChannel">setReadChannel</a>() to set the current read channel of <a href="qprocess.html">QProcess</a>.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QProcess.StandardOutput</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">The standard output (stdout) of the running process.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.StandardError</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">The standard error (stderr) of the running process.</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="ProcessChannelMode-enum" />QProcess.ProcessChannelMode</h3><p>This enum describes the process channel modes of <a href="qprocess.html">QProcess</a>. Pass one of these values to <a href="qprocess.html#setReadChannelMode">setReadChannelMode</a>() to set the current read channel mode.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QProcess.SeparateChannels</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top"><a href="qprocess.html">QProcess</a> manages the output of the running process, keeping standard output and standard error data in separate internal buffers. You can select the <a href="qprocess.html">QProcess</a>'s current read channel by calling <a href="qprocess.html#setReadChannel">setReadChannel</a>(). This is the default channel mode of <a href="qprocess.html">QProcess</a>.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.MergedChannels</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top"><a href="qprocess.html">QProcess</a> merges the output of the running process into the standard output channel (<tt>stdout</tt>). The standard error channel (<tt>stderr</tt>) will not receive any data. The standard output and standard error data of the running process are interleaved.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.ForwardedChannels</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top"><a href="qprocess.html">QProcess</a> forwards the output of the running process onto the main process. Anything the child process writes to its standard output and standard error will be written to the standard output and standard error of the main process.</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qprocess.html#setReadChannelMode">setReadChannelMode</a>().</p>
<h3 class="fn"><a name="ProcessError-enum" />QProcess.ProcessError</h3><p>This enum describes the different types of errors that are reported by <a href="qprocess.html">QProcess</a>.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QProcess.FailedToStart</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.Crashed</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">The process crashed some time after starting successfully.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.Timedout</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">The last waitFor...() function timed out. The state of <a href="qprocess.html">QProcess</a> is unchanged, and you can try calling waitFor...() again.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.WriteError</tt></td>
<td align="center" valign="top"><tt>4</tt></td>
<td valign="top">An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.ReadError</tt></td>
<td align="center" valign="top"><tt>3</tt></td>
<td valign="top">An error occurred when attempting to read from the process. For example, the process may not be running.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.UnknownError</tt></td>
<td align="center" valign="top"><tt>5</tt></td>
<td valign="top">An unknown error occurred. This is the default return value of <a href="qprocess.html#error">error</a>().</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qprocess.html#error">error</a>().</p>
<h3 class="fn"><a name="ProcessState-enum" />QProcess.ProcessState</h3><p>This enum describes the different states of <a href="qprocess.html">QProcess</a>.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QProcess.NotRunning</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">The process is not running.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.Starting</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">The process is starting, but the program has not yet been invoked.</td>
</tr>
<tr>
<td valign="top"><tt>QProcess.Running</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">The process is running and is ready for reading and writing.</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qprocess.html#state">state</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QProcess" />QProcess.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qprocess.html">QProcess</a> object with the given <i>parent</i>.</p>
<h3 class="fn"><a name="atEnd" />bool QProcess.atEnd (<i>self</i>)</h3><h3 class="fn"><a name="bytesAvailable" />long QProcess.bytesAvailable (<i>self</i>)</h3><h3 class="fn"><a name="bytesToWrite" />long QProcess.bytesToWrite (<i>self</i>)</h3><h3 class="fn"><a name="canReadLine" />bool QProcess.canReadLine (<i>self</i>)</h3><h3 class="fn"><a name="close" />QProcess.close (<i>self</i>)</h3><p>Closes all communication with the process. After calling this function, <a href="qprocess.html">QProcess</a> will no longer emit <a href="qiodevice.html#readyRead">readyRead</a>(), and data can no longer be read or written.</p>
<p>Reimplemented from <a href="qiodevice.html#close">QIODevice</a>.</p>
<h3 class="fn"><a name="closeReadChannel" />QProcess.closeReadChannel (<i>self</i>, <a href="qprocess.html#ProcessChannel-enum">ProcessChannel</a>&#160;<i>channel</i>)</h3><p>Closes the read channel <i>channel</i>. After calling this function, <a href="qprocess.html">QProcess</a> will no longer receive data on the channel. Any data that has already been received is still available for reading.</p>
<p>Call this function to save memory, if you are not interested in the output of the process.</p>
<p>See also <a href="qprocess.html#closeWriteChannel">closeWriteChannel</a>() and <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="closeWriteChannel" />QProcess.closeWriteChannel (<i>self</i>)</h3><p>Schedules the write channel of <a href="qprocess.html">QProcess</a> to be closed. The channel will close once all data has been written to the process. After calling this function, any attempts to write to the process will fail.</p>
<p>Closing the write channel is necessary for programs that read input data until the channel has been closed. For example, the program "more" is used to display text data in a console on both Unix and Windows. But it will not display the text data until <a href="qprocess.html">QProcess</a>'s write channel has been closed. Example:</p>
<pre>
    QProcess more;
    more.start("more");
    more.write("Text to display");
    more.closeWriteChannel();
    // QProcess will emit readyRead() once "more" starts printing
</pre>
<p>The write channel is implicitly opened when <a href="qprocess.html#start">start</a>() is called.</p>
<p>See also <a href="qprocess.html#closeReadChannel">closeReadChannel</a>().</p>
<h3 class="fn"><a name="environment" /><a href="qstringlist.html">QStringList</a> QProcess.environment (<i>self</i>)</h3><p>Returns the environment that <a href="qprocess.html">QProcess</a> will use when starting a process, or an empty <a href="qstringlist.html">QStringList</a> if no environment has been set using <a href="qprocess.html#setEnvironment">setEnvironment</a>(). If no environment has been set, the environment of the calling process will be used.</p>
<p>See also <a href="qprocess.html#setEnvironment">setEnvironment</a>() and <a href="qprocess.html#systemEnvironment">systemEnvironment</a>().</p>
<h3 class="fn"><a name="error" /><a href="qprocess.html#ProcessError-enum">ProcessError</a> QProcess.error (<i>self</i>)</h3><p>Returns the type of error that occurred last.</p>
<p>See also <a href="qprocess.html#state">state</a>().</p>
<h3 class="fn"><a name="execute" />int QProcess.execute (<a href="qstring.html">QString</a>&#160;<i>program</i>, <a href="qstringlist.html">QStringList</a>&#160;<i>arguments</i>)</h3><p>Starts the program <i>program</i> with the arguments <i>arguments</i> in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.</p>
<p>The environment and working directory are inherited by the calling process.</p>
<p>On Windows, arguments that contain spaces are wrapped in quotes.</p>
<h3 class="fn"><a name="execute-2" />int QProcess.execute (<a href="qstring.html">QString</a>&#160;<i>program</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Starts the program <i>program</i> in a new process. <i>program</i> is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces.</p>
<h3 class="fn"><a name="exitCode" />int QProcess.exitCode (<i>self</i>)</h3><p>Returns the exit code of the last process that finished.</p>
<h3 class="fn"><a name="exitStatus" /><a href="qprocess.html#ExitStatus-enum">ExitStatus</a> QProcess.exitStatus (<i>self</i>)</h3><p>Returns the exit status of the last process that finished.</p>
<p>On Windows, if the process was terminated with TerminateProcess() from another application this function will still return <a href="qprocess.html#ExitStatus-enum">NormalExit</a> unless the exit code is less than 0.</p>
<p>This function was introduced in Qt 4.1.</p>
<h3 class="fn"><a name="isSequential" />bool QProcess.isSequential (<i>self</i>)</h3><h3 class="fn"><a name="kill" />QProcess.kill (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void kill()</tt>.</p><p>Kills the current process, causing it to exit immediately.</p>
<p>On Windows, kill() uses TerminateProcess, and on Unix and Mac OS X, the SIGKILL signal is sent to the process.</p>
<p>See also <a href="qprocess.html#terminate">terminate</a>().</p>
<h3 class="fn"><a name="pid" />long QProcess.pid (<i>self</i>)</h3><p>Returns the native process identifier for the running process, if available. If no process is currently running, 0 is returned.</p>
<h3 class="fn"><a name="readAllStandardError" /><a href="qbytearray.html">QByteArray</a> QProcess.readAllStandardError (<i>self</i>)</h3><p>Regardless of the current read channel, this function returns all data available from the standard error of the process as a <a href="qbytearray.html">QByteArray</a>.</p>
<p>See also <a href="qprocess.html#readyReadStandardError">readyReadStandardError</a>(), <a href="qprocess.html#readAllStandardOutput">readAllStandardOutput</a>(), <a href="qprocess.html#readChannel">readChannel</a>(), and <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="readAllStandardOutput" /><a href="qbytearray.html">QByteArray</a> QProcess.readAllStandardOutput (<i>self</i>)</h3><p>Regardless of the current read channel, this function returns all data available from the standard output of the process as a <a href="qbytearray.html">QByteArray</a>.</p>
<p>See also <a href="qprocess.html#readyReadStandardOutput">readyReadStandardOutput</a>(), <a href="qprocess.html#readAllStandardError">readAllStandardError</a>(), <a href="qprocess.html#readChannel">readChannel</a>(), and <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="readChannel" /><a href="qprocess.html#ProcessChannel-enum">ProcessChannel</a> QProcess.readChannel (<i>self</i>)</h3><p>Returns the current read channel of the <a href="qprocess.html">QProcess</a>.</p>
<p>See also <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="readChannelMode" /><a href="qprocess.html#ProcessChannelMode-enum">ProcessChannelMode</a> QProcess.readChannelMode (<i>self</i>)</h3><p>Returns the read channel mode of the <a href="qprocess.html">QProcess</a>.</p>
<p>See also <a href="qprocess.html#setReadChannelMode">setReadChannelMode</a>(), <a href="qprocess.html#ProcessChannelMode-enum">ProcessChannelMode</a>, and <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="readData" />object QProcess.readData (<i>self</i>, long&#160;<i>maxlen</i>)</h3><h3 class="fn"><a name="setEnvironment" />QProcess.setEnvironment (<i>self</i>, <a href="qstringlist.html">QStringList</a>&#160;<i>environment</i>)</h3><p>Sets the environment that <a href="qprocess.html">QProcess</a> will use when starting a process to <i>environment</i>. <i>environment</i> is a list of key=value pairs. Example:</p>
<pre>
    QProcess process;
    QStringList env = QProcess.systemEnvironment();
    env &lt;&lt; "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable
    env.replaceInStrings(QRegExp("^PATH=(.*)", false), "PATH=\\1;C:\\Bin"); // Add Bin to PATH
    process.setEnvironment(env);
    process.start("myapp");
</pre>
<p>See also <a href="qprocess.html#environment">environment</a>() and <a href="qprocess.html#systemEnvironment">systemEnvironment</a>().</p>
<h3 class="fn"><a name="setProcessState" />QProcess.setProcessState (<i>self</i>, <a href="qprocess.html#ProcessState-enum">ProcessState</a>&#160;<i>state</i>)</h3><p>Sets the current state of the <a href="qprocess.html">QProcess</a> to the <i>state</i> specified.</p>
<p>See also <a href="qprocess.html#state">state</a>().</p>
<h3 class="fn"><a name="setReadChannel" />QProcess.setReadChannel (<i>self</i>, <a href="qprocess.html#ProcessChannel-enum">ProcessChannel</a>&#160;<i>channel</i>)</h3><p>Sets the current read channel of the <a href="qprocess.html">QProcess</a> to the given <i>channel</i>. The current input channel is used by the functions <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readAll">readAll</a>(), <a href="qiodevice.html#readLine">readLine</a>(), and <a href="qiodevice.html#getChar">getChar</a>(). It also determines which channel triggers <a href="qprocess.html">QProcess</a> to emit <a href="qiodevice.html#readyRead">readyRead</a>().</p>
<p>Changing the read channel will clear the unget buffer.</p>
<p>See also <a href="qprocess.html#readChannel">readChannel</a>().</p>
<h3 class="fn"><a name="setReadChannelMode" />QProcess.setReadChannelMode (<i>self</i>, <a href="qprocess.html#ProcessChannelMode-enum">ProcessChannelMode</a>&#160;<i>mode</i>)</h3><p>Sets the read channel mode of the <a href="qprocess.html">QProcess</a> to the <i>mode</i> specified. This mode will be used the next time <a href="qprocess.html#start">start</a>() is called. For example:</p>
<pre>
    QProcess builder;
    builder.setReadChannelMode(QProcess.MergedChannels);
    builder.start("make", QStringList() &lt;&lt; "-j2");

    if (!builder.waitForFinished())
        qDebug() &lt;&lt; "Make failed:" &lt;&lt; builder.errorString();
    else
        qDebug() &lt;&lt; "Make output:" &lt;&lt; builder.readAll();
</pre>
<p>See also <a href="qprocess.html#readChannelMode">readChannelMode</a>(), <a href="qprocess.html#ProcessChannelMode-enum">ProcessChannelMode</a>, and <a href="qprocess.html#setReadChannel">setReadChannel</a>().</p>
<h3 class="fn"><a name="setupChildProcess" />QProcess.setupChildProcess (<i>self</i>)</h3><p>This function is called in the child process context just before the program is executed on Unix or Mac OS X (i.e., after <i>fork()</i>, but before <i>execve()</i>). Reimplement this function to do last minute initialization of the child process. Example:</p>
<pre>
    class SandboxProcess : public QProcess
    {
        ...
     protected:
         void setupChildProcess();
        ...
    };

    void SandboxProcess.setupChildProcess()
    {
        // Drop all privileges in the child process, and enter
        // a chroot jail.
    #if defined Q_OS_UNIX
        .setgroups(0, 0);
        .chroot("/etc/safe");
        .chdir("/");
        .setgid(safeGid);
        .setuid(safeUid);
        .umask(0);
    #endif
    }
</pre>
<p><b>Warning:</b> This function is called by <a href="qprocess.html">QProcess</a> on Unix and Mac OS X only. On Windows, it is not called.</p>
<h3 class="fn"><a name="setWorkingDirectory" />QProcess.setWorkingDirectory (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>dir</i>)</h3><p>Sets the working directory to <i>dir</i>. <a href="qprocess.html">QProcess</a> will start the process in this directory. The default behavior is to start the process in the working directory of the calling process.</p>
<p>See also <a href="qprocess.html#workingDirectory">workingDirectory</a>() and <a href="qprocess.html#start">start</a>().</p>
<h3 class="fn"><a name="start" />QProcess.start (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>program</i>, <a href="qstringlist.html">QStringList</a>&#160;<i>arguments</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a>&#160;<i>mode</i>&#160;=&#160;QIODevice.ReadWrite)</h3><p>Starts the program <i>program</i> in a new process, passing the command line arguments in <i>arguments</i>. The <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> is set to <i>mode</i>. <a href="qprocess.html">QProcess</a> will immediately enter the Starting state. If the process starts successfully, <a href="qprocess.html">QProcess</a> will emit <a href="qprocess.html#started">started</a>(); otherwise, <a href="qprocess.html#error">error</a>() will be emitted.</p>
<p>On Windows, arguments that contain spaces are wrapped in quotes.</p>
<p>See also <a href="qprocess.html#pid">pid</a>() and <a href="qprocess.html#started">started</a>().</p>
<h3 class="fn"><a name="start-2" />QProcess.start (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>program</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a>&#160;<i>mode</i>&#160;=&#160;QIODevice.ReadWrite)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Starts the program <i>program</i> in a new process. <i>program</i> is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces. For example:</p>
<pre>
    QProcess process;
    process.start("del /s *.txt");
    // same as process.start("del", QStringList() &lt;&lt; "/s" &lt;&lt; "*.txt");
    ...
</pre>
<p>The <i>program</i> string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process. For example:</p>
<pre>
    QProcess process;
    process.start("dir \"My Documents\"");
</pre>
<p>Note that, on Windows, quotes need to be both escaped and quoted. For example, the above code would be specified in the following way to ensure that <tt>"My Documents"</tt> is used as the argument to the <tt>dir</tt> executable:</p>
<pre>
    QProcess process;
    process.start("dir \"\"\"My Documents\"\"\"");
</pre>
<p>The <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> is set to <i>mode</i>.</p>
<h3 class="fn"><a name="startDetached" />bool QProcess.startDetached (<a href="qstring.html">QString</a>&#160;<i>program</i>, <a href="qstringlist.html">QStringList</a>&#160;<i>arguments</i>)</h3><p>Starts the program <i>program</i> with the arguments <i>arguments</i> in a new process, and detaches from it. Returns true on success; otherwise returns false. If the calling process exits, the detached process will continue to live.</p>
<p>On Unix, the started process will run in its own session and act like a daemon. On Windows, it will run as a regular standalone process.</p>
<p>On Windows, arguments that contain spaces are wrapped in quotes.</p>
<h3 class="fn"><a name="startDetached-2" />bool QProcess.startDetached (<a href="qstring.html">QString</a>&#160;<i>program</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Starts the program <i>program</i> in a new process. <i>program</i> is a single string of text containing both the program name and its arguments. The arguments are separated by one or more spaces.</p>
<p>The <i>program</i> string can also contain quotes, to ensure that arguments containing spaces are correctly supplied to the new process.</p>
<h3 class="fn"><a name="state" /><a href="qprocess.html#ProcessState-enum">ProcessState</a> QProcess.state (<i>self</i>)</h3><p>Returns the current state of the process.</p>
<p>See also <a href="qprocess.html#stateChanged">stateChanged</a>() and <a href="qprocess.html#error">error</a>().</p>
<h3 class="fn"><a name="systemEnvironment" /><a href="qstringlist.html">QStringList</a> QProcess.systemEnvironment ()</h3><p>Returns the environment of the calling process as a list of key=value pairs. Example:</p>
<pre>
    QStringList environment = QProcess.systemEnvironment();
    // environment = {"PATH=/usr/bin:/usr/local/bin",
                      "USER=greg", "HOME=/home/greg"}
</pre>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qprocess.html#environment">environment</a>() and <a href="qprocess.html#setEnvironment">setEnvironment</a>().</p>
<h3 class="fn"><a name="terminate" />QProcess.terminate (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void terminate()</tt>.</p><p>Attempts to terminate the process.</p>
<p>The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).</p>
<p>On Windows, terminate() posts a WM_CLOSE message to the process, and on Unix and Mac OS X the SIGTERM signal is sent.</p>
<p>See also <a href="qprocess.html#kill">kill</a>().</p>
<h3 class="fn"><a name="waitForBytesWritten" />bool QProcess.waitForBytesWritten (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</h3><h3 class="fn"><a name="waitForFinished" />bool QProcess.waitForFinished (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</h3><p>Blocks until the process has finished and the <a href="qprocess.html#finished">finished</a>() signal has been emitted, or until <i>msecs</i> milliseconds have passed.</p>
<p>Returns true if the process finished; otherwise returns false (if the operation timed out or if an error occurred).</p>
<p>This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.</p>
<p><b>Warning:</b> Calling this function from the main (GUI) thread might cause your user interface to freeze.</p>
<p>If msecs is -1, this function will not time out.</p>
<p>See also <a href="qprocess.html#finished">finished</a>(), <a href="qprocess.html#waitForStarted">waitForStarted</a>(), <a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>(), and <a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
<h3 class="fn"><a name="waitForReadyRead" />bool QProcess.waitForReadyRead (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</h3><h3 class="fn"><a name="waitForStarted" />bool QProcess.waitForStarted (<i>self</i>, int&#160;<i>msecs</i>&#160;=&#160;30000)</h3><p>Blocks until the process has started and the <a href="qprocess.html#started">started</a>() signal has been emitted, or until <i>msecs</i> milliseconds have passed.</p>
<p>Returns true if the process was started successfully; otherwise returns false (if the operation timed out or if an error occurred).</p>
<p>This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.</p>
<p><b>Warning:</b> Calling this function from the main (GUI) thread might cause your user interface to freeze.</p>
<p>If msecs is -1, this function will not time out.</p>
<p>See also <a href="qprocess.html#started">started</a>(), <a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>(), <a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>(), and <a href="qprocess.html#waitForFinished">waitForFinished</a>().</p>
<h3 class="fn"><a name="workingDirectory" /><a href="qstring.html">QString</a> QProcess.workingDirectory (<i>self</i>)</h3><p>Returns the working directory that the <a href="qprocess.html">QProcess</a> will enter before the program has started.</p>
<p>See also <a href="qprocess.html#setWorkingDirectory">setWorkingDirectory</a>().</p>
<h3 class="fn"><a name="writeData" />long QProcess.writeData (<i>self</i>, str&#160;<i>data</i>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="error-2" />void error (QProcess::ProcessError)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This signal is emitted when an error occurs with the process. The specified <i>error</i> describes the type of error that occurred.</p>
<h3 class="fn"><a name="finished" />void finished (int)</h3><p>This signal is emitted when the process finishes. <i>exitCode</i> is the exit code of the process, and <i>exitStatus</i> is the exit status. After the process has finished, the buffers in <a href="qprocess.html">QProcess</a> are still intact. You can still read any data that the process may have written before it finished.</p>
<p>See also <a href="qprocess.html#exitStatus">exitStatus</a>().</p>
<h3 class="fn"><a name="finished-2" />void finished (int,QProcess::ExitStatus)</h3><h3 class="fn"><a name="readyReadStandardError" />void readyReadStandardError ()</h3><p>This signal is emitted when the process has made new data available through its standard error channel (<tt>stderr</tt>). It is emitted regardless of the current <a href="qprocess.html#readChannel">read channel</a>.</p>
<p>See also <a href="qprocess.html#readAllStandardError">readAllStandardError</a>() and <a href="qprocess.html#readChannel">readChannel</a>().</p>
<h3 class="fn"><a name="readyReadStandardOutput" />void readyReadStandardOutput ()</h3><p>This signal is emitted when the process has made new data available through its standard output channel (<tt>stdout</tt>). It is emitted regardless of the current <a href="qprocess.html#readChannel">read channel</a>.</p>
<p>See also <a href="qprocess.html#readAllStandardOutput">readAllStandardOutput</a>() and <a href="qprocess.html#readChannel">readChannel</a>().</p>
<h3 class="fn"><a name="started" />void started ()</h3><p>This signal is emitted by <a href="qprocess.html">QProcess</a> when the process has started, and <a href="qprocess.html#state">state</a>() returns <a href="qprocess.html#ProcessState-enum">Running</a>.</p>
<h3 class="fn"><a name="stateChanged" />void stateChanged (QProcess::ProcessState)</h3><p>This signal is emitted whenever the state of <a href="qprocess.html">QProcess</a> changes. The <i>newState</i> argument is the state <a href="qprocess.html">QProcess</a> changed to.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>