]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/process.tex
sorting support for generic version (patch 1765087 from Bo)
[wxWidgets.git] / docs / latex / wx / process.tex
1 \section{\class{wxProcess}}\label{wxprocess}
2
3 The objects of this class are used in conjunction with the
4 \helpref{wxExecute}{wxexecute} function. When a wxProcess object is passed to
5 wxExecute(), its \helpref{OnTerminate()}{wxprocessonterminate} virtual method
6 is called when the process terminates. This allows the program to be
7 (asynchronously) notified about the process termination and also retrieve its
8 exit status which is unavailable from wxExecute() in the case of
9 asynchronous execution.
10
11 Please note that if the process termination notification is processed by the
12 parent, it is responsible for deleting the wxProcess object which sent it.
13 However, if it is not processed, the object will delete itself and so the
14 library users should only delete those objects whose notifications have been
15 processed (and call \helpref{Detach()}{wxprocessdetach} for others).
16
17 wxProcess also supports IO redirection of the child process. For this, you have
18 to call its \helpref{Redirect}{wxprocessredirect} method before passing it to
19 \helpref{wxExecute}{wxexecute}. If the child process was launched successfully,
20 \helpref{GetInputStream}{wxprocessgetinputstream},
21 \helpref{GetOutputStream}{wxprocessgetoutputstream} and
22 \helpref{GetErrorStream}{wxprocessgeterrorstream} can then be used to retrieve
23 the streams corresponding to the child process standard output, input and
24 error output respectively.
25
26 \perlnote{In wxPerl this class has an additional {\tt Destroy} method,
27 for explicit destruction.}
28
29 \wxheading{Derived from}
30
31 \helpref{wxEvtHandler}{wxevthandler}
32
33 \wxheading{Include files}
34
35 <wx/process.h>
36
37 \wxheading{Library}
38
39 \helpref{wxBase}{librarieslist}
40
41 \wxheading{See also}
42
43 \helpref{wxExecute}{wxexecute}\\
44 \helpref{exec sample}{sampleexec}
45
46 \latexignore{\rtfignore{\wxheading{Members}}}
47
48 \membersection{wxProcess::wxProcess}\label{wxprocessctor}
49
50 \func{}{wxProcess}{\param{wxEvtHandler *}{ parent = NULL}, \param{int}{ id = -1}}
51
52 \func{}{wxProcess}{\param{int }{flags}}
53
54 Constructs a process object. {\it id} is only used in the case you want to
55 use wxWidgets events. It identifies this object, or another window that will
56 receive the event.
57
58 If the {\it parent} parameter is different from NULL, it will receive
59 a wxEVT\_END\_PROCESS notification event (you should insert EVT\_END\_PROCESS
60 macro in the event table of the parent to handle it) with the given {\it id}.
61
62 The second constructor creates an object without any associated parent (and
63 hence no id neither) but allows to specify the {\it flags} which can have the
64 value of {\tt wxPROCESS\_DEFAULT} or {\tt wxPROCESS\_REDIRECT}. Specifying the
65 former value has no particular effect while using the latter one is equivalent
66 to calling \helpref{Redirect}{wxprocessredirect}.
67
68 \wxheading{Parameters}
69
70 \docparam{parent}{The event handler parent.}
71
72 \docparam{id}{id of an event.}
73
74 \docparam{flags}{either {\tt wxPROCESS\_DEFAULT} or {\tt wxPROCESS\_REDIRECT}}
75
76 \membersection{wxProcess::\destruct{wxProcess}}\label{wxprocessdtor}
77
78 \func{}{\destruct{wxProcess}}{\void}
79
80 Destroys the wxProcess object.
81
82 \membersection{wxProcess::CloseOutput}\label{wxprocesscloseoutput}
83
84 \func{void}{CloseOutput}{\void}
85
86 Closes the output stream (the one connected to the stdin of the child
87 process). This function can be used to indicate to the child process that
88 there is no more data to be read - usually, a filter program will only
89 terminate when the input stream is closed.
90
91 \membersection{wxProcess::Detach}\label{wxprocessdetach}
92
93 \func{void}{Detach}{\void}
94
95 Normally, a wxProcess object is deleted by its parent when it receives the
96 notification about the process termination. However, it might happen that the
97 parent object is destroyed before the external process is terminated (e.g. a
98 window from which this external process was launched is closed by the user)
99 and in this case it {\bf should not delete} the wxProcess object, but
100 {\bf should call Detach()} instead. After the wxProcess object is detached
101 from its parent, no notification events will be sent to the parent and the
102 object will delete itself upon reception of the process termination
103 notification.
104
105 \membersection{wxProcess::GetErrorStream}\label{wxprocessgeterrorstream}
106
107 \constfunc{wxInputStream* }{GetErrorStream}{\void}
108
109 Returns an input stream which corresponds to the standard error output (stderr)
110 of the child process.
111
112 \membersection{wxProcess::GetInputStream}\label{wxprocessgetinputstream}
113
114 \constfunc{wxInputStream* }{GetInputStream}{\void}
115
116 It returns an input stream corresponding to the standard output stream of the
117 subprocess. If it is NULL, you have not turned on the redirection.
118 See \helpref{wxProcess::Redirect}{wxprocessredirect}.
119
120 \membersection{wxProcess::GetOutputStream}\label{wxprocessgetoutputstream}
121
122 \constfunc{wxOutputStream* }{GetOutputStream}{\void}
123
124 It returns an output stream correspoding to the input stream of the subprocess.
125 If it is NULL, you have not turned on the redirection.
126 See \helpref{wxProcess::Redirect}{wxprocessredirect}.
127
128 \membersection{wxProcess::IsErrorAvailable}\label{wxprocessiserroravailable}
129
130 \constfunc{bool}{IsErrorAvailable}{\void}
131
132 Returns {\tt true} if there is data to be read on the child process standard
133 error stream.
134
135 \wxheading{See also}
136
137 \helpref{IsInputAvailable}{wxprocessisinputavailable}
138
139 \membersection{wxProcess::IsInputAvailable}\label{wxprocessisinputavailable}
140
141 \constfunc{bool}{IsInputAvailable}{\void}
142
143 Returns {\tt true} if there is data to be read on the child process standard
144 output stream. This allows to write simple (and extremely inefficient)
145 polling-based code waiting for a better mechanism in future wxWidgets versions.
146
147 See the \helpref{exec sample}{sampleexec} for an example of using this
148 function.
149
150 \wxheading{See also}
151
152 \helpref{IsInputOpened}{wxprocessisinputopened}
153
154 \membersection{wxProcess::IsInputOpened}\label{wxprocessisinputopened}
155
156 \constfunc{bool}{IsInputOpened}{\void}
157
158 Returns {\tt true} if the child process standard output stream is opened.
159
160 \membersection{wxProcess::Kill}\label{wxprocesskill}
161
162 \func{static wxKillError}{Kill}{\param{int}{ pid}, \param{wxSignal}{ signal = wxSIGNONE}, \param{int }{flags = wxKILL\_NOCHILDREN}}
163
164 Send the specified signal to the given process. Possible signal values are:
165
166 \begin{verbatim}
167 enum wxSignal
168 {
169 wxSIGNONE = 0, // verify if the process exists under Unix
170 wxSIGHUP,
171 wxSIGINT,
172 wxSIGQUIT,
173 wxSIGILL,
174 wxSIGTRAP,
175 wxSIGABRT,
176 wxSIGEMT,
177 wxSIGFPE,
178 wxSIGKILL, // forcefully kill, dangerous!
179 wxSIGBUS,
180 wxSIGSEGV,
181 wxSIGSYS,
182 wxSIGPIPE,
183 wxSIGALRM,
184 wxSIGTERM // terminate the process gently
185 };
186 \end{verbatim}
187
188 {\tt wxSIGNONE}, {\tt wxSIGKILL} and {\tt wxSIGTERM} have the same meaning
189 under both Unix and Windows but all the other signals are equivalent to
190 {\tt wxSIGTERM} under Windows.
191
192 The {\it flags} parameter can be wxKILL\_NOCHILDREN (the default),
193 or wxKILL\_CHILDREN, in which case the child processes of this
194 process will be killed too. Note that under Unix, for wxKILL\_CHILDREN
195 to work you should have created the process passing wxEXEC\_MAKE\_GROUP\_LEADER.
196
197 Returns the element of {\tt wxKillError} enum:
198
199 \begin{verbatim}
200 enum wxKillError
201 {
202 wxKILL_OK, // no error
203 wxKILL_BAD_SIGNAL, // no such signal
204 wxKILL_ACCESS_DENIED, // permission denied
205 wxKILL_NO_PROCESS, // no such process
206 wxKILL_ERROR // another, unspecified error
207 };
208 \end{verbatim}
209
210 \wxheading{See also}
211
212 \helpref{wxProcess::Exists}{wxprocessexists},\rtfsp
213 \helpref{wxKill}{wxkill},\rtfsp
214 \helpref{Exec sample}{sampleexec}
215
216 \membersection{wxProcess::Exists}\label{wxprocessexists}
217
218 \func{static bool}{Exists}{\param{int}{ pid}}
219
220 Returns {\tt true} if the given process exists in the system.
221
222 \wxheading{See also}
223
224 \helpref{wxProcess::Kill}{wxprocesskill},\rtfsp
225 \helpref{Exec sample}{sampleexec}
226
227 \membersection{wxProcess::OnTerminate}\label{wxprocessonterminate}
228
229 \func{void}{OnTerminate}{\param{int}{ pid}, \param{int}{ status}}
230
231 It is called when the process with the pid {\it pid} finishes.
232 It raises a wxWidgets event when it isn't overridden.
233
234 \docparam{pid}{The pid of the process which has just terminated.}
235
236 \docparam{status}{The exit code of the process.}
237
238 \membersection{wxProcess::Open}\label{wxprocessopen}
239
240 \func{static wxProcess *}{Open}{\param{const wxString\& }{cmd}, \param{int }{flags = wxEXEC\_ASYNC}}
241
242 This static method replaces the standard {\tt popen()} function: it launches
243 the process specified by the {\it cmd} parameter and returns the wxProcess
244 object which can be used to retrieve the streams connected to the standard
245 input, output and error output of the child process.
246
247 If the process couldn't be launched, {\tt NULL} is returned. Note that in any
248 case the returned pointer should {\bf not} be deleted, rather the process
249 object will be destroyed automatically when the child process terminates. This
250 does mean that the child process should be told to quit before the main program
251 exits to avoid memory leaks.
252
253 \wxheading{Parameters}
254
255 \docparam{cmd}{The command to execute, including optional arguments.}
256 \docparam{flags}{The flags to pass to \helpref{wxExecute}{wxexecute}.
257 NOTE: wxEXEC\_SYNC should not be used.}
258
259 \wxheading{Return value}
260
261 A pointer to new wxProcess object or {\tt NULL} on error.
262
263 \wxheading{See also}
264
265 \helpref{wxExecute}{wxexecute}
266
267 \membersection{wxProcess::GetPid}\label{wxprocessgetpid}
268
269 \constfunc{long}{GetPid}{\void}
270
271 Returns the process ID of the process launched by \helpref{Open}{wxprocessopen}.
272
273 \membersection{wxProcess::Redirect}\label{wxprocessredirect}
274
275 \func{void}{Redirect}{\void}
276
277 Turns on redirection. wxExecute will try to open a couple of pipes
278 to catch the subprocess stdio. The caught input stream is returned by
279 GetOutputStream() as a non-seekable stream. The caught output stream is returned
280 by GetInputStream() as a non-seekable stream.
281