]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/process.tex
Typo fixed in tsizer.tex; no change to setup0.h
[wxWidgets.git] / docs / latex / wx / process.tex
CommitLineData
eafc087e
GL
1\section{\class{wxProcess}}\label{wxprocess}
2
fe25efa3 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
BP
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 stdandard output, input and
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
44\membersection{wxProcess::wxProcess}\label{wxprocessconstr}
45
e8482f24 46\func{}{wxProcess}{\param{wxEvtHandler *}{ parent = NULL}, \param{int}{ id = -1}}
eafc087e
GL
47
48Constructs a process object. {\it id} is only used in the case you want to
3972fb49
JS
49use wxWindows events. It identifies this object, or another window that will
50receive the event.
eafc087e 51
7e84f02d
VZ
52If the {\it parent} parameter is different from NULL, it will receive
53a wxEVT\_END\_PROCESS notification event (you should insert EVT\_END\_PROCESS
54macro in the event table of the parent to handle it) with the given {\it id}.
55
eafc087e
GL
56\wxheading{Parameters}
57
58\docparam{parent}{The event handler parent.}
59
60\docparam{id}{id of an event.}
61
62\membersection{wxProcess::\destruct{wxProcess}}
63
64\func{}{\destruct{wxProcess}}{\void}
65
66Destroys the wxProcess object.
67
f6bcfd97
BP
68\membersection{wxProcess::CloseOutput}\label{wxprocesscloseoutput}
69
70\func{void}{CloseOutput}{\void}
71
72Closes the output stream (the one connected to the stdin of the child
73process). This function can be used to indicate to the child process that
74there is no more data to be read - usually, a filter program will only
75terminate when the input stream is closed.
76
7e84f02d
VZ
77\membersection{wxProcess::Detach}\label{wxprocessdetach}
78
79\func{void}{Detach}{\void}
80
81Normally, a wxProcess object is deleted by its parent when it receives the
82notification about the process termination. However, it might happen that the
83parent object is destroyed before the external process is terminated (e.g. a
84window from which this external process was launched is closed by the user)
85and in this case it {\bf should not delete} the wxProcess object, but
86{\bf should call Detach()} instead. After the wxProcess object is detached
87from its parent, no notification events will be sent to the parent and the
88object will delete itself upon reception of the process termination
89notification.
90
f6bcfd97
BP
91\membersection{wxProcess::GetErrorStream}\label{wxprocessgeterrorstream}
92
93\constfunc{wxInputStream* }{GetErrorStream}{\void}
94
95Returns an input stream which corresponds to the standard error output (stderr)
96of the child process.
97
70dc22dc
GL
98\membersection{wxProcess::GetInputStream}\label{wxprocessgetinputstream}
99
100\constfunc{wxInputStream* }{GetInputStream}{\void}
101
fe25efa3 102It returns an input stream corresponding to the standard output stream of the
f6bcfd97 103subprocess. If it is NULL, you have not turned on the redirection.
e8482f24 104See \helpref{wxProcess::Redirect}{wxprocessredirect}.
70dc22dc 105
66f55ec6 106\membersection{wxProcess::GetOutputStream}\label{wxprocessgetoutputstream}
70dc22dc 107
66f55ec6 108\constfunc{wxOutputStream* }{GetOutputStream}{\void}
70dc22dc 109
f6bcfd97 110It returns an output stream correspoding to the input stream of the subprocess.
e8482f24
GL
111If it is NULL, you have not turned on the redirection.
112See \helpref{wxProcess::Redirect}{wxprocessredirect}.
70dc22dc 113
50567b69
VZ
114\membersection{wxProcess::Kill}\label{wxprocesskill}
115
116\func{static wxKillError}{Kill}{\param{int}{ pid}, \param{wxSignal}{ signal = wxSIGNONE}}
117
118Send the specified signal to the given process. Possible signal values are:
119
120\begin{verbatim}
121enum wxSignal
122{
123 wxSIGNONE = 0, // verify if the process exists under Unix
124 wxSIGHUP,
125 wxSIGINT,
126 wxSIGQUIT,
127 wxSIGILL,
128 wxSIGTRAP,
129 wxSIGABRT,
130 wxSIGEMT,
131 wxSIGFPE,
132 wxSIGKILL, // forcefully kill, dangerous!
133 wxSIGBUS,
134 wxSIGSEGV,
135 wxSIGSYS,
136 wxSIGPIPE,
137 wxSIGALRM,
138 wxSIGTERM // terminate the process gently
139};
140\end{verbatim}
141
142{\tt wxSIGNONE}, {\tt wxSIGKILL} and {\tt wxSIGTERM} have the same meaning
143under both Unix and Windows but all the other signals are equivalent to
144{\tt wxSIGTERM} under Windows.
145
146Returns the element of {\tt wxKillError} enum:
147
148\begin{verbatim}
149enum wxKillError
150{
151 wxKILL_OK, // no error
152 wxKILL_BAD_SIGNAL, // no such signal
153 wxKILL_ACCESS_DENIED, // permission denied
154 wxKILL_NO_PROCESS, // no such process
155 wxKILL_ERROR // another, unspecified error
156};
157\end{verbatim}
158
159\wxheading{See also}
160
161\helpref{wxProcess::Exists}{wxprocessexists},\rtfsp
162\helpref{wxKill}{wxkill},\rtfsp
cb35465e 163\helpref{Exec sample}{sampleexec}
50567b69 164
9722642d 165\membersection{wxProcess::Exists}\label{wxprocessexists}
50567b69
VZ
166
167\func{static bool}{Exists}{\param{int}{ pid}}
168
169Returns {\tt TRUE} if the given process exists in the system.
170
171\wxheading{See also}
172
173\helpref{wxProcess::Kill}{wxprocesskill},\rtfsp
cb35465e 174\helpref{Exec sample}{sampleexec}
50567b69 175
eafc087e
GL
176\membersection{wxProcess::OnTerminate}\label{wxprocessonterminate}
177
7e84f02d 178\constfunc{void}{OnTerminate}{\param{int}{ pid}, \param{int}{ status}}
eafc087e
GL
179
180It is called when the process with the pid {\it pid} finishes.
f6bcfd97 181It raises a wxWindows event when it isn't overridden.
eafc087e 182
7e84f02d
VZ
183\docparam{pid}{The pid of the process which has just terminated.}
184
185\docparam{status}{The exit code of the process.}
3972fb49 186
e8482f24
GL
187\membersection{wxProcess::Redirect}\label{wxprocessredirect}
188
189\func{void}{Redirect}{\void}
190
fe25efa3 191Turns on redirection. wxExecute will try to open a couple of pipes
e8482f24
GL
192to catch the subprocess stdio. The caught input stream is returned by
193GetOutputStream() as a non-seekable stream. The caught output stream is returned
194by GetInputStream() as a non-seekable stream.
66f55ec6 195