]>
git.saurik.com Git - wxWidgets.git/blob - src/common/process.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Process termination classes
4 // Author: Guilhem Lavaux
5 // Modified by: Vadim Zeitlin to check error codes, added Detach() method
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "process.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #include "wx/process.h"
33 // ----------------------------------------------------------------------------
34 // event tables and such
35 // ----------------------------------------------------------------------------
37 DEFINE_EVENT_TYPE(wxEVT_END_PROCESS
)
39 IMPLEMENT_DYNAMIC_CLASS(wxProcess
, wxEvtHandler
)
40 IMPLEMENT_DYNAMIC_CLASS(wxProcessEvent
, wxEvent
)
42 // ============================================================================
43 // wxProcess implementation
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 void wxProcess::Init(wxEvtHandler
*parent
, int id
, int flags
)
53 SetNextHandler(parent
);
56 m_redirect
= (flags
& wxPROCESS_REDIRECT
) != 0;
61 m_outputStream
= NULL
;
62 #endif // wxUSE_STREAMS
66 wxProcess
*wxProcess::Open(const wxString
& cmd
, int flags
)
68 wxProcess
*process
= new wxProcess(wxPROCESS_REDIRECT
);
69 if ( !wxExecute(cmd
, flags
, process
) )
71 // couldn't launch the process
79 // ----------------------------------------------------------------------------
80 // wxProcess termination
81 // ----------------------------------------------------------------------------
83 wxProcess::~wxProcess()
88 delete m_outputStream
;
89 #endif // wxUSE_STREAMS
92 void wxProcess::OnTerminate(int pid
, int status
)
94 wxProcessEvent
event(m_id
, pid
, status
);
96 if ( !ProcessEvent(event
) )
98 //else: the object which processed the event is responsible for deleting
102 void wxProcess::Detach()
104 SetNextHandler(NULL
);
107 // ----------------------------------------------------------------------------
108 // process IO redirection
109 // ----------------------------------------------------------------------------
113 void wxProcess::SetPipeStreams(wxInputStream
*inputSstream
,
114 wxOutputStream
*outputStream
,
115 wxInputStream
*errorStream
)
117 m_inputStream
= inputSstream
;
118 m_errorStream
= errorStream
;
119 m_outputStream
= outputStream
;
122 #endif // wxUSE_STREAMS
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
129 wxKillError
wxProcess::Kill(int pid
, wxSignal sig
)
132 (void)wxKill(pid
, sig
, &rc
);
138 bool wxProcess::Exists(int pid
)
140 switch ( Kill(pid
, wxSIGNONE
) )
143 case wxKILL_ACCESS_DENIED
:
148 case wxKILL_BAD_SIGNAL
:
149 wxFAIL_MSG( _T("unexpected wxProcess::Kill() return code") );
152 case wxKILL_NO_PROCESS
: