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