1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxProcess class
4 // Author: Guilhem Lavaux
5 // Modified by: Vadim Zeitlin to check error codes, added Detach() method
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROCESSH__
13 #define _WX_PROCESSH__
16 #pragma interface "process.h"
20 #include "wx/object.h"
24 #include "wx/stream.h"
27 // ----------------------------------------------------------------------------
28 // wxProcessEvent: event used with wxProcess
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxProcessEvent
: public wxEvent
33 DECLARE_DYNAMIC_CLASS(wxProcessEvent
)
36 wxProcessEvent(int id
= 0, int pid
= 0, int exitcode
= 0) : wxEvent(id
)
38 m_eventType
= wxEVT_END_PROCESS
;
40 m_exitcode
= exitcode
;
44 // PID of process which terminated
45 int GetPid() { return m_pid
; }
48 int GetExitCode() { return m_exitcode
; }
51 int m_pid
, m_exitcode
;
54 // ----------------------------------------------------------------------------
55 // A wxProcess object should be passed to wxExecute - than its OnTerminate()
56 // function will be called when the process terminates.
57 // ----------------------------------------------------------------------------
59 class WXDLLEXPORT wxProcess
: public wxEvtHandler
61 DECLARE_DYNAMIC_CLASS(wxProcess
)
64 wxProcess(wxEvtHandler
*parent
= (wxEvtHandler
*) NULL
, int id
= -1)
65 { Init(parent
, id
, FALSE
); }
66 wxProcess(wxEvtHandler
*parent
, bool redirect
)
67 { Init(parent
, -1, redirect
); }
71 // may be overridden to be notified about process termination
72 virtual void OnTerminate(int pid
, int status
);
74 // call this before passing the object to wxExecute() to redirect the
75 // launched process stdin/stdout, then use GetInputStream() and
76 // GetOutputStream() to get access to them
77 void Redirect() { m_redirect
= TRUE
; }
78 bool IsRedirected() const { return m_redirect
; }
80 // detach from the parent - should be called by the parent if it's deleted
81 // before the process it started terminates
86 wxInputStream
*GetInputStream() const { return m_inputStream
; }
87 wxInputStream
*GetErrorStream() const { return m_errorStream
; }
88 wxOutputStream
*GetOutputStream() const { return m_outputStream
; }
90 // close the output stream indicating that nothing more will be written
91 void CloseOutput() { delete m_outputStream
; m_outputStream
= NULL
; }
93 // implementation only (for wxExecute)
94 void SetPipeStreams(wxInputStream
*inStream
,
95 wxOutputStream
*outStream
,
96 wxInputStream
*errStream
);
97 #endif // wxUSE_STREAMS
100 void Init(wxEvtHandler
*parent
, int id
, bool redirect
);
105 wxInputStream
*m_inputStream
,
107 wxOutputStream
*m_outputStream
;
108 #endif // wxUSE_STREAMS
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 BEGIN_DECLARE_EVENT_TYPES()
118 DECLARE_EVENT_TYPE(wxEVT_END_PROCESS
, 440)
119 END_DECLARE_EVENT_TYPES()
121 typedef void (wxObject::*wxProcessEventFunction
)(wxProcessEvent
&);
123 #define EVT_END_PROCESS(id, func) \
124 DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),