]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_process.i
Added Brian Victor's Patch
[wxWidgets.git] / wxPython / src / _process.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _process.i
3// Purpose: SWIG interface stuff for wxProcess and wxExecute
4//
5// Author: Robin Dunn
6//
7// Created: 18-June-1999
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19%{
20%}
21
22//---------------------------------------------------------------------------
23
24enum
25{
26 // no redirection
27 wxPROCESS_DEFAULT = 0,
28
29 // redirect the IO of the child process
30 wxPROCESS_REDIRECT = 1
31};
32
33enum wxKillError
34{
35 wxKILL_OK, // no error
36 wxKILL_BAD_SIGNAL, // no such signal
37 wxKILL_ACCESS_DENIED, // permission denied
38 wxKILL_NO_PROCESS, // no such process
39 wxKILL_ERROR // another, unspecified error
40};
41
42enum wxSignal
43{
44 wxSIGNONE = 0, // verify if the process exists under Unix
45 wxSIGHUP,
46 wxSIGINT,
47 wxSIGQUIT,
48 wxSIGILL,
49 wxSIGTRAP,
50 wxSIGABRT,
51 wxSIGIOT = wxSIGABRT, // another name
52 wxSIGEMT,
53 wxSIGFPE,
54 wxSIGKILL,
55 wxSIGBUS,
56 wxSIGSEGV,
57 wxSIGSYS,
58 wxSIGPIPE,
59 wxSIGALRM,
60 wxSIGTERM
61
62 // further signals are different in meaning between different Unix systems
63};
64
65
66//---------------------------------------------------------------------------
67
68
69%{
70IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
71%}
72
73
74%name(Process)class wxPyProcess : public wxEvtHandler {
75public:
76 // kill the process with the given PID
77 static wxKillError Kill(int pid, wxSignal sig = wxSIGTERM);
78
79 // test if the given process exists
80 static bool Exists(int pid);
81
82 // this function replaces the standard popen() one: it launches a process
83 // asynchronously and allows the caller to get the streams connected to its
84 // std{in|out|err}
85 //
86 // on error NULL is returned, in any case the process object will be
87 // deleted automatically when the process terminates and should *not* be
88 // deleted by the caller
89 static wxPyProcess *Open(const wxString& cmd, int flags = wxEXEC_ASYNC);
90
91
92 %addtofunc wxPyProcess "self._setCallbackInfo(self, Process)"
93 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
94
95 void _setCallbackInfo(PyObject* self, PyObject* _class);
96
97 void base_OnTerminate(int pid, int status);
98
99 // call Redirect before passing the object to wxExecute() to redirect the
100 // launched process stdin/stdout, then use GetInputStream() and
101 // GetOutputStream() to get access to them
102 void Redirect();
103 bool IsRedirected();
104
105
106 // detach from the parent - should be called by the parent if it's deleted
107 // before the process it started terminates
108 void Detach();
109
110 wxInputStream *GetInputStream();
111 wxInputStream *GetErrorStream();
112 wxOutputStream *GetOutputStream();
113
114 void CloseOutput();
115
dd9f7fea 116 // return True if the child process stdout is not closed
d14a1e28
RD
117 bool IsInputOpened() const;
118
dd9f7fea 119 // return True if any input is available on the child process stdout/err
d14a1e28
RD
120 bool IsInputAvailable() const;
121 bool IsErrorAvailable() const;
122};
123
124//---------------------------------------------------------------------------
125
126
127class wxProcessEvent : public wxEvent {
128public:
129 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
130 int GetPid();
131 int GetExitCode();
132 int m_pid, m_exitcode;
133};
134
135
136%constant wxEventType wxEVT_END_PROCESS;
137
138%pythoncode {
139EVT_END_PROCESS = wx.PyEventBinder( wxEVT_END_PROCESS, 1 )
140}
141
142//---------------------------------------------------------------------------
143
144enum
145{
146 // execute the process asynchronously
147 wxEXEC_ASYNC = 0,
148
149 // execute it synchronously, i.e. wait until it finishes
150 wxEXEC_SYNC = 1,
151
152 // under Windows, don't hide the child even if it's IO is redirected (this
153 // is done by default)
154 wxEXEC_NOHIDE = 2,
155
156 // under Unix, if the process is the group leader then killing -pid kills
157 // all children as well as pid
158 wxEXEC_MAKE_GROUP_LEADER = 4
159};
160
161
162long wxExecute(const wxString& command,
163 int flags = wxEXEC_ASYNC,
164 wxPyProcess *process = NULL);
165
166
167//---------------------------------------------------------------------------
168%init %{
169 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
170%}
171//---------------------------------------------------------------------------