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 // A wxProcess object should be passed to wxExecute - than its OnTerminate()
29 // function will be called when the process terminates.
30 // ----------------------------------------------------------------------------
32 class WXDLLEXPORT wxProcess
: public wxEvtHandler
34 DECLARE_DYNAMIC_CLASS(wxProcess
)
37 wxProcess(wxEvtHandler
*parent
= (wxEvtHandler
*) NULL
, int id
= -1)
38 { Init(parent
, id
, FALSE
); }
39 wxProcess(wxEvtHandler
*parent
, bool redirect
)
40 { Init(parent
, -1, redirect
); }
44 // may be overridden to be notified about process termination
45 virtual void OnTerminate(int pid
, int status
);
47 // call this before passing the object to wxExecute() to redirect the
48 // launched process stdin/stdout, then use GetInputStream() and
49 // GetOutputStream() to get access to them
50 void Redirect() { m_redirect
= TRUE
; }
51 bool IsRedirected() const { return m_redirect
; }
53 // detach from the parent - should be called by the parent if it's deleted
54 // before the process it started terminates
59 wxInputStream
*GetInputStream() const { return m_inputStream
; }
60 wxInputStream
*GetErrorStream() const { return m_errorStream
; }
61 wxOutputStream
*GetOutputStream() const { return m_outputStream
; }
63 // close the output stream indicating that nothing more will be written
64 void CloseOutput() { delete m_outputStream
; m_outputStream
= NULL
; }
66 // implementation only (for wxExecute)
67 void SetPipeStreams(wxInputStream
*inStream
,
68 wxOutputStream
*outStream
,
69 wxInputStream
*errStream
);
70 #endif // wxUSE_STREAMS
73 void Init(wxEvtHandler
*parent
, int id
, bool redirect
);
78 wxInputStream
*m_inputStream
,
80 wxOutputStream
*m_outputStream
;
81 #endif // wxUSE_STREAMS
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 BEGIN_DECLARE_EVENT_TYPES()
91 DECLARE_EVENT_TYPE(wxEVT_END_PROCESS
, 440)
92 END_DECLARE_EVENT_TYPES()
94 class WXDLLEXPORT wxProcessEvent
: public wxEvent
97 wxProcessEvent(int id
= 0, int pid
= 0, int exitcode
= 0) : wxEvent(id
)
99 m_eventType
= wxEVT_END_PROCESS
;
101 m_exitcode
= exitcode
;
105 // PID of process which terminated
106 int GetPid() { return m_pid
; }
109 int GetExitCode() { return m_exitcode
; }
112 int m_pid
, m_exitcode
;
114 DECLARE_DYNAMIC_CLASS(wxProcessEvent
)
117 typedef void (wxObject::*wxProcessEventFunction
)(wxProcessEvent
&);
119 #define EVT_END_PROCESS(id, func) \
120 DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),