]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/process.tex
Added EVT_MOVE_START, EVT_MOVE_END (wxMSW only for now)
[wxWidgets.git] / docs / latex / wx / process.tex
... / ...
CommitLineData
1\section{\class{wxProcess}}\label{wxprocess}
2
3The objects of this class are used in conjunction with the
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).
16
17wxProcess also supports IO redirection of the child process. For this, you have
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
22\helpref{GetErrorStream}{wxprocessgeterrorstream} can then be used to retrieve
23the streams corresponding to the child process standard output, input and
24error output respectively.
25
26\perlnote{In wxPerl this class has an additional {\tt Destroy} method,
27for 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
54Constructs a process object. {\it id} is only used in the case you want to
55use wxWidgets events. It identifies this object, or another window that will
56receive the event.
57
58If the {\it parent} parameter is different from NULL, it will receive
59a wxEVT\_END\_PROCESS notification event (you should insert EVT\_END\_PROCESS
60macro in the event table of the parent to handle it) with the given {\it id}.
61
62The second constructor creates an object without any associated parent (and
63hence no id neither) but allows to specify the {\it flags} which can have the
64value of {\tt wxPROCESS\_DEFAULT} or {\tt wxPROCESS\_REDIRECT}. Specifying the
65former value has no particular effect while using the latter one is equivalent
66to 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
80Destroys the wxProcess object.
81
82\membersection{wxProcess::CloseOutput}\label{wxprocesscloseoutput}
83
84\func{void}{CloseOutput}{\void}
85
86Closes the output stream (the one connected to the stdin of the child
87process). This function can be used to indicate to the child process that
88there is no more data to be read - usually, a filter program will only
89terminate when the input stream is closed.
90
91\membersection{wxProcess::Detach}\label{wxprocessdetach}
92
93\func{void}{Detach}{\void}
94
95Normally, a wxProcess object is deleted by its parent when it receives the
96notification about the process termination. However, it might happen that the
97parent object is destroyed before the external process is terminated (e.g. a
98window from which this external process was launched is closed by the user)
99and in this case it {\bf should not delete} the wxProcess object, but
100{\bf should call Detach()} instead. After the wxProcess object is detached
101from its parent, no notification events will be sent to the parent and the
102object will delete itself upon reception of the process termination
103notification.
104
105\membersection{wxProcess::GetErrorStream}\label{wxprocessgeterrorstream}
106
107\constfunc{wxInputStream* }{GetErrorStream}{\void}
108
109Returns an input stream which corresponds to the standard error output (stderr)
110of the child process.
111
112\membersection{wxProcess::GetInputStream}\label{wxprocessgetinputstream}
113
114\constfunc{wxInputStream* }{GetInputStream}{\void}
115
116It returns an input stream corresponding to the standard output stream of the
117subprocess. If it is NULL, you have not turned on the redirection.
118See \helpref{wxProcess::Redirect}{wxprocessredirect}.
119
120\membersection{wxProcess::GetOutputStream}\label{wxprocessgetoutputstream}
121
122\constfunc{wxOutputStream* }{GetOutputStream}{\void}
123
124It returns an output stream correspoding to the input stream of the subprocess.
125If it is NULL, you have not turned on the redirection.
126See \helpref{wxProcess::Redirect}{wxprocessredirect}.
127
128\membersection{wxProcess::IsErrorAvailable}\label{wxprocessiserroravailable}
129
130\constfunc{bool}{IsErrorAvailable}{\void}
131
132Returns {\tt true} if there is data to be read on the child process standard
133error 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
143Returns {\tt true} if there is data to be read on the child process standard
144output stream. This allows to write simple (and extremely inefficient)
145polling-based code waiting for a better mechanism in future wxWidgets versions.
146
147See the \helpref{exec sample}{sampleexec} for an example of using this
148function.
149
150\wxheading{See also}
151
152\helpref{IsInputOpened}{wxprocessisinputopened}
153
154\membersection{wxProcess::IsInputOpened}\label{wxprocessisinputopened}
155
156\constfunc{bool}{IsInputOpened}{\void}
157
158Returns {\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
164Send the specified signal to the given process. Possible signal values are:
165
166\begin{verbatim}
167enum 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
189under both Unix and Windows but all the other signals are equivalent to
190{\tt wxSIGTERM} under Windows.
191
192The {\it flags} parameter can be wxKILL\_NOCHILDREN (the default),
193or wxKILL\_CHILDREN, in which case the child processes of this
194process will be killed too. Note that under Unix, for wxKILL\_CHILDREN
195to work you should have created the process passing wxEXEC\_MAKE\_GROUP\_LEADER.
196
197Returns the element of {\tt wxKillError} enum:
198
199\begin{verbatim}
200enum 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
220Returns {\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
231It is called when the process with the pid {\it pid} finishes.
232It 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
242This static method replaces the standard {\tt popen()} function: it launches
243the process specified by the {\it cmd} parameter and returns the wxProcess
244object which can be used to retrieve the streams connected to the standard
245input, output and error output of the child process.
246
247If the process couldn't be launched, {\tt NULL} is returned. Note that in any
248case the returned pointer should {\bf not} be deleted, rather the process
249object will be destroyed automatically when the child process terminates. This
250does mean that the child process should be told to quit before the main program
251exits 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
261A 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
271Returns 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
277Turns on redirection. wxExecute will try to open a couple of pipes
278to catch the subprocess stdio. The caught input stream is returned by
279GetOutputStream() as a non-seekable stream. The caught output stream is returned
280by GetInputStream() as a non-seekable stream.
281