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 // Process Event handling
28 class WXDLLEXPORT wxProcessEvent
: public wxEvent
30 DECLARE_DYNAMIC_CLASS(wxProcessEvent
)
33 wxProcessEvent(int id
= 0, int pid
= 0, int exitcode
= 0) : wxEvent(id
)
35 m_eventType
= wxEVT_END_PROCESS
;
37 m_exitcode
= exitcode
;
41 // PID of process which terminated
42 int GetPid() { return m_pid
; }
45 int GetExitCode() { return m_exitcode
; }
48 int m_pid
, m_exitcode
;
51 // A wxProcess object should be passed to wxExecute - than its OnTerminate()
52 // function will be called when the process terminates.
53 class WXDLLEXPORT wxProcess
: public wxEvtHandler
55 DECLARE_DYNAMIC_CLASS(wxProcess
)
58 wxProcess(wxEvtHandler
*parent
= (wxEvtHandler
*) NULL
, int id
= -1)
59 { Init(parent
, id
, FALSE
); }
60 wxProcess(wxEvtHandler
*parent
, bool redirect
)
61 { Init(parent
, -1, redirect
); }
65 // may be overridden to be notified about process termination
66 virtual void OnTerminate(int pid
, int status
);
68 // call this before passing the object to wxExecute() to redirect the
69 // launched process stdin/stdout, then use GetInputStream() and
70 // GetOutputStream() to get access to them
71 void Redirect() { m_redirect
= TRUE
; }
72 bool IsRedirected() const { return m_redirect
; }
74 // detach from the parent - should be called by the parent if it's deleted
75 // before the process it started terminates
80 wxInputStream
*GetInputStream() const { return m_inputStream
; }
81 wxInputStream
*GetErrorStream() const { return m_errorStream
; }
82 wxOutputStream
*GetOutputStream() const { return m_outputStream
; }
84 // close the output stream indicating that nothing more will be written
85 void CloseOutput() { delete m_outputStream
; m_outputStream
= NULL
; }
87 // implementation only (for wxExecute)
88 void SetPipeStreams(wxInputStream
*inStream
,
89 wxOutputStream
*outStream
,
90 wxInputStream
*errStream
);
91 #endif // wxUSE_STREAMS
94 void Init(wxEvtHandler
*parent
, int id
, bool redirect
);
99 wxInputStream
*m_inputStream
,
101 wxOutputStream
*m_outputStream
;
102 #endif // wxUSE_STREAMS
107 typedef void (wxObject::*wxProcessEventFunction
)(wxProcessEvent
&);
109 #define EVT_END_PROCESS(id, func) \
110 wxEventTableEntry( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),