The objects of this class are used in conjunction with wxExecute function. When a wxProcess object is passed to wxExecute(), its OnTerminate() virtual method is called when the process terminates. This allows the program to be (asynchronously) notified about the process termination and also retrieve its exit status which is unavailable from wxExecute() in the case of asynchronous execution.
Please note that if the process termination notification is processed by the parent, it is responsible for deleting the wxProcess object which sent it. However, if it is not processed, the object will delete itself and so the library users should only delete those objects whose notifications have been processed (and call Detach() for others).
wxProcess also supports IO redirection of the child process. For this, you have to call its Redirect method before passing it to wxExecute. If the child process was launched successfully, GetInputStream, GetOutputStream and GetErrorStream can then be used to retrieve the streams corresponding to the child process stdandard output, input and error output respectively.
Derived from
Include files
<wx/process.h>
See also
Members
wxProcess::wxProcess
wxProcess::~wxProcess
wxProcess::CloseOutput
wxProcess::Detach
wxProcess::GetErrorStream
wxProcess::GetInputStream
wxProcess::GetOutputStream
wxProcess::OnTerminate
wxProcess::Redirect
wxProcess(wxEvtHandler * parent = NULL, int id = -1)
Constructs a process object. id is only used in the case you want to use wxWindows events. It identifies this object, or another window that will receive the event.
If the parent parameter is different from NULL, it will receive a wxEVT_END_PROCESS notification event (you should insert EVT_END_PROCESS macro in the event table of the parent to handle it) with the given id.
Parameters
parent
id
~wxProcess()
Destroys the wxProcess object.
void CloseOutput()
Closes the output stream (the one connected to the stdin of the child process). This function can be used to indicate to the child process that there is no more data to be read - usually, a filter program will only terminate when the input stream is closed.
void Detach()
Normally, a wxProcess object is deleted by its parent when it receives the notification about the process termination. However, it might happen that the parent object is destroyed before the external process is terminated (e.g. a window from which this external process was launched is closed by the user) and in this case it should not delete the wxProcess object, but should call Detach() instead. After the wxProcess object is detached from its parent, no notification events will be sent to the parent and the object will delete itself upon reception of the process termination notification.
wxInputStream* GetErrorStream() const
Returns an input stream which corresponds to the standard error output (stderr) of the child process.
wxInputStream* GetInputStream() const
It returns a output stream corresponding to the standard output stream of the subprocess. If it is NULL, you have not turned on the redirection. See wxProcess::Redirect.
wxOutputStream* GetOutputStream() const
It returns an output stream correspoding to the input stream of the subprocess. If it is NULL, you have not turned on the redirection. See wxProcess::Redirect.
void OnTerminate(int pid, int status) const
It is called when the process with the pid pid finishes. It raises a wxWindows event when it isn't overridden.
pid
status
void Redirect()
It turns on the redirection, wxExecute will try to open a couple of pipes to catch the subprocess stdio. The caught input stream is returned by GetOutputStream() as a non-seekable stream. The caught output stream is returned by GetInputStream() as a non-seekable stream.