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"
22 #include "wx/stream.h"
25 #include "wx/utils.h" // for wxSignal
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
35 wxProcess(wxEvtHandler
*parent
= (wxEvtHandler
*) NULL
, int id
= -1)
36 { Init(parent
, id
, FALSE
); }
37 wxProcess(wxEvtHandler
*parent
, bool redirect
)
38 { Init(parent
, -1, redirect
); }
42 // may be overridden to be notified about process termination
43 virtual void OnTerminate(int pid
, int status
);
45 // call this before passing the object to wxExecute() to redirect the
46 // launched process stdin/stdout, then use GetInputStream() and
47 // GetOutputStream() to get access to them
48 void Redirect() { m_redirect
= TRUE
; }
49 bool IsRedirected() const { return m_redirect
; }
51 // detach from the parent - should be called by the parent if it's deleted
52 // before the process it started terminates
57 wxInputStream
*GetInputStream() const { return m_inputStream
; }
58 wxInputStream
*GetErrorStream() const { return m_errorStream
; }
59 wxOutputStream
*GetOutputStream() const { return m_outputStream
; }
61 // close the output stream indicating that nothing more will be written
62 void CloseOutput() { delete m_outputStream
; m_outputStream
= NULL
; }
64 // implementation only (for wxExecute)
65 void SetPipeStreams(wxInputStream
*inStream
,
66 wxOutputStream
*outStream
,
67 wxInputStream
*errStream
);
68 #endif // wxUSE_STREAMS
70 // kill the process with the given PID
71 static wxKillError
Kill(int pid
, wxSignal sig
= wxSIGTERM
);
73 // test if the given process exists
74 static bool Exists(int pid
);
77 void Init(wxEvtHandler
*parent
, int id
, bool redirect
);
82 wxInputStream
*m_inputStream
,
84 wxOutputStream
*m_outputStream
;
85 #endif // wxUSE_STREAMS
89 DECLARE_DYNAMIC_CLASS(wxProcess
)
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 BEGIN_DECLARE_EVENT_TYPES()
97 DECLARE_EVENT_TYPE(wxEVT_END_PROCESS
, 440)
98 END_DECLARE_EVENT_TYPES()
100 class WXDLLEXPORT wxProcessEvent
: public wxEvent
103 wxProcessEvent(int id
= 0, int pid
= 0, int exitcode
= 0) : wxEvent(id
)
105 m_eventType
= wxEVT_END_PROCESS
;
107 m_exitcode
= exitcode
;
111 // PID of process which terminated
112 int GetPid() { return m_pid
; }
115 int GetExitCode() { return m_exitcode
; }
118 int m_pid
, m_exitcode
;
120 DECLARE_DYNAMIC_CLASS(wxProcessEvent
)
123 typedef void (wxObject::*wxProcessEventFunction
)(wxProcessEvent
&);
125 #define EVT_END_PROCESS(id, func) \
126 DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),