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"
22 #include "wx/stream.h"
24 // Process Event handling
25 class WXDLLEXPORT wxProcessEvent
: public wxEvent
27 DECLARE_DYNAMIC_CLASS(wxProcessEvent
)
30 wxProcessEvent(int id
= 0, int pid
= 0, int exitcode
= 0) : wxEvent(id
)
32 m_eventType
= wxEVT_END_PROCESS
;
34 m_exitcode
= exitcode
;
38 // PID of process which terminated
39 int GetPid() { return m_pid
; }
42 int GetExitCode() { return m_exitcode
; }
45 int m_pid
, m_exitcode
;
48 // A wxProcess object should be passed to wxExecute - than its OnTerminate()
49 // function will be called when the process terminates.
50 class WXDLLEXPORT wxProcess
: public wxEvtHandler
52 DECLARE_DYNAMIC_CLASS(wxProcess
)
55 wxProcess(wxEvtHandler
*parent
= (wxEvtHandler
*) NULL
, int id
= -1)
56 { Init(parent
, id
, FALSE
); }
57 wxProcess(wxEvtHandler
*parent
, bool redirect
)
58 { Init(parent
, -1, redirect
); }
62 // may be overridden to be notified about process termination
63 virtual void OnTerminate(int pid
, int status
);
65 // call this before passing the object to wxExecute() to redirect the
66 // launched process stdin/stdout, then use GetInputStream() and
67 // GetOutputStream() to get access to them
68 void Redirect() { m_redirect
= TRUE
; }
69 bool IsRedirected() const { return m_redirect
; }
71 // detach from the parent - should be called by the parent if it's deleted
72 // before the process it started terminates
76 wxInputStream
*GetInputStream() const { return m_inputStream
; }
77 wxOutputStream
*GetOutputStream() const { return m_outputStream
; }
79 // implementation only (for wxExecute)
80 void SetPipeStreams(wxInputStream
*inStream
, wxOutputStream
*outStream
);
83 void Init(wxEvtHandler
*parent
, int id
, bool redirect
);
87 wxInputStream
*m_inputStream
;
88 wxOutputStream
*m_outputStream
;
93 typedef void (wxObject::*wxProcessEventFunction
)(wxProcessEvent
&);
95 #define EVT_END_PROCESS(id, func) { wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL},