]>
git.saurik.com Git - wxWidgets.git/blob - interface/process.h
5487817c8dcfbb1ce208c3baa836a1fc1119cd4b
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxProcess class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 The objects of this class are used in conjunction with the
14 wxExecute function. When a wxProcess object is passed to
15 wxExecute(), its wxProcess::OnTerminate virtual method
16 is called when the process terminates. This allows the program to be
17 (asynchronously) notified about the process termination and also retrieve its
18 exit status which is unavailable from wxExecute() in the case of
19 asynchronous execution.
21 Please note that if the process termination notification is processed by the
22 parent, it is responsible for deleting the wxProcess object which sent it.
23 However, if it is not processed, the object will delete itself and so the
24 library users should only delete those objects whose notifications have been
25 processed (and call wxProcess::Detach for others).
27 wxProcess also supports IO redirection of the child process. For this, you have
28 to call its wxProcess::Redirect method before passing it to
29 wxExecute. If the child process was launched successfully,
30 wxProcess::GetInputStream,
31 wxProcess::GetOutputStream and
32 wxProcess::GetErrorStream can then be used to retrieve
33 the streams corresponding to the child process standard output, input and
34 error output respectively.
36 @b wxPerl note: In wxPerl this class has an additional @c Destroy method,
37 for explicit destruction.
40 @category{appmanagement}
43 wxExecute, @ref overview_sampleexec "exec sample"
45 class wxProcess
: public wxEvtHandler
50 Constructs a process object. @a id is only used in the case you want to
51 use wxWidgets events. It identifies this object, or another window that will
53 If the @a parent parameter is different from @NULL, it will receive
54 a wxEVT_END_PROCESS notification event (you should insert EVT_END_PROCESS
55 macro in the event table of the parent to handle it) with the given @e id.
56 The second constructor creates an object without any associated parent (and
57 hence no id neither) but allows to specify the @a flags which can have the
58 value of @c wxPROCESS_DEFAULT or @c wxPROCESS_REDIRECT. Specifying the
59 former value has no particular effect while using the latter one is equivalent
60 to calling Redirect().
63 The event handler parent.
67 either wxPROCESS_DEFAULT or wxPROCESS_REDIRECT
69 wxProcess(wxEvtHandler
* parent
= NULL
, int id
= -1);
74 Destroys the wxProcess object.
79 Closes the output stream (the one connected to the stdin of the child
80 process). This function can be used to indicate to the child process that
81 there is no more data to be read - usually, a filter program will only
82 terminate when the input stream is closed.
87 Normally, a wxProcess object is deleted by its parent when it receives the
88 notification about the process termination. However, it might happen that the
89 parent object is destroyed before the external process is terminated (e.g. a
90 window from which this external process was launched is closed by the user)
91 and in this case it @b should not delete the wxProcess object, but
92 @b should call Detach() instead. After the wxProcess object is detached
93 from its parent, no notification events will be sent to the parent and the
94 object will delete itself upon reception of the process termination
100 Returns @true if the given process exists in the system.
102 @see Kill(), @ref overview_sampleexec "Exec sample"
104 static bool Exists(int pid
);
107 Returns an input stream which corresponds to the standard error output (stderr)
108 of the child process.
110 wxInputStream
* GetErrorStream() const;
113 It returns an input stream corresponding to the standard output stream of the
114 subprocess. If it is @NULL, you have not turned on the redirection.
117 wxInputStream
* GetInputStream() const;
120 It returns an output stream correspoding to the input stream of the subprocess.
121 If it is @NULL, you have not turned on the redirection.
124 wxOutputStream
* GetOutputStream() const;
127 Returns the process ID of the process launched by Open().
132 Returns @true if there is data to be read on the child process standard
135 @see IsInputAvailable()
137 bool IsErrorAvailable() const;
140 Returns @true if there is data to be read on the child process standard
141 output stream. This allows to write simple (and extremely inefficient)
142 polling-based code waiting for a better mechanism in future wxWidgets versions.
143 See the @ref overview_sampleexec "exec sample" for an example of using this
148 bool IsInputAvailable() const;
151 Returns @true if the child process standard output stream is opened.
153 bool IsInputOpened() const;
156 Send the specified signal to the given process. Possible signal values are:
158 @c wxSIGNONE, @c wxSIGKILL and @c wxSIGTERM have the same meaning
159 under both Unix and Windows but all the other signals are equivalent to
160 @c wxSIGTERM under Windows.
161 The @a flags parameter can be wxKILL_NOCHILDREN (the default),
162 or wxKILL_CHILDREN, in which case the child processes of this
163 process will be killed too. Note that under Unix, for wxKILL_CHILDREN
164 to work you should have created the process passing wxEXEC_MAKE_GROUP_LEADER.
165 Returns the element of @c wxKillError enum:
167 @see Exists(), wxKill, @ref overview_sampleexec "Exec sample"
169 static wxKillError
Kill(int pid
, wxSignal signal
= wxSIGNONE
,
170 int flags
= wxKILL_NOCHILDREN
);
173 It is called when the process with the pid
176 It raises a wxWidgets event when it isn't overridden.
179 The pid of the process which has just terminated.
181 The exit code of the process.
183 void OnTerminate(int pid
, int status
);
186 This static method replaces the standard @c popen() function: it launches
187 the process specified by the @a cmd parameter and returns the wxProcess
188 object which can be used to retrieve the streams connected to the standard
189 input, output and error output of the child process.
190 If the process couldn't be launched, @NULL is returned. Note that in any
191 case the returned pointer should @b not be deleted, rather the process
192 object will be destroyed automatically when the child process terminates. This
193 does mean that the child process should be told to quit before the main program
194 exits to avoid memory leaks.
197 The command to execute, including optional arguments.
199 The flags to pass to wxExecute.
200 NOTE: wxEXEC_SYNC should not be used.
202 @returns A pointer to new wxProcess object or @NULL on error.
206 static wxProcess
* Open(const wxString
& cmd
,
207 int flags
= wxEXEC_ASYNC
);
210 Turns on redirection. wxExecute will try to open a couple of pipes
211 to catch the subprocess stdio. The caught input stream is returned by
212 GetOutputStream() as a non-seekable stream. The caught output stream is returned
213 by GetInputStream() as a non-seekable stream.
220 @class wxProcessEvent
223 A process event is sent when a process is terminated.
229 wxProcess, @ref overview_eventhandlingoverview
231 class wxProcessEvent
: public wxEvent
235 Constructor. Takes a wxProcessObject or window id, a process id and an
238 wxProcessEvent(int id
= 0, int pid
= 0, int exitcode
= 0);
241 Returns the exist status.
246 Returns the process id.