1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface stuff for wxProcess and wxExecute
7 // Created: 18-June-1999
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
22 //---------------------------------------------------------------------------
27 wxPROCESS_DEFAULT = 0,
29 // redirect the IO of the child process
30 wxPROCESS_REDIRECT = 1
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
44 wxKILL_NOCHILDREN = 0, // don't kill children
45 wxKILL_CHILDREN = 1 // kill children
51 wxSIGNONE = 0, // verify if the process exists under Unix
58 wxSIGIOT = wxSIGABRT, // another name
69 // further signals are different in meaning between different Unix systems
73 //---------------------------------------------------------------------------
77 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
81 %rename(Process) wxPyProcess;
82 class wxPyProcess : public wxEvtHandler {
84 // kill the process with the given PID
85 static wxKillError Kill(int pid,
86 wxSignal sig = wxSIGTERM,
87 int flags = wxKILL_NOCHILDREN);
89 // test if the given process exists
90 static bool Exists(int pid);
92 // this function replaces the standard popen() one: it launches a process
93 // asynchronously and allows the caller to get the streams connected to its
96 // on error NULL is returned, in any case the process object will be
97 // deleted automatically when the process terminates and should *not* be
98 // deleted by the caller
99 static wxPyProcess *Open(const wxString& cmd, int flags = wxEXEC_ASYNC);
102 %pythonAppend wxPyProcess setCallbackInfo(Process) "; self.this.own(False)"
103 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
106 void _setCallbackInfo(PyObject* self, PyObject* _class);
110 long , GetPid() const,
111 "get the process ID of the process executed by Open()", "");
114 void OnTerminate(int pid, int status);
115 %MAKE_BASE_FUNC(Process, OnTerminate);
117 // call Redirect before passing the object to wxExecute() to redirect the
118 // launched process stdin/stdout, then use GetInputStream() and
119 // GetOutputStream() to get access to them
124 // detach from the parent - should be called by the parent if it's deleted
125 // before the process it started terminates
128 wxInputStream *GetInputStream();
129 wxInputStream *GetErrorStream();
130 wxOutputStream *GetOutputStream();
134 // return True if the child process stdout is not closed
135 bool IsInputOpened() const;
137 // return True if any input is available on the child process stdout/err
138 bool IsInputAvailable() const;
139 bool IsErrorAvailable() const;
141 %property(ErrorStream, GetErrorStream, doc="See `GetErrorStream`");
142 %property(InputStream, GetInputStream, doc="See `GetInputStream`");
143 %property(OutputStream, GetOutputStream, doc="See `GetOutputStream`");
145 %property(InputOpened, IsInputOpened);
146 %property(InputAvailable, IsInputAvailable);
147 %property(ErrorAvailable, IsErrorAvailable);
150 //---------------------------------------------------------------------------
153 class wxProcessEvent : public wxEvent {
155 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
158 int m_pid, m_exitcode;
160 %property(ExitCode, GetExitCode, doc="See `GetExitCode`");
161 %property(Pid, GetPid, doc="See `GetPid`");
165 %constant wxEventType wxEVT_END_PROCESS;
168 EVT_END_PROCESS = wx.PyEventBinder( wxEVT_END_PROCESS, 1 )
171 //---------------------------------------------------------------------------
175 // execute the process asynchronously
178 // execute it synchronously, i.e. wait until it finishes
181 // under Windows, don't hide the child even if it's IO is redirected (this
182 // is done by default)
185 // under Unix, if the process is the group leader then killing -pid kills
186 // all children as well as pid
187 wxEXEC_MAKE_GROUP_LEADER = 4,
189 // by default synchronous execution disables all program windows to avoid
190 // that the user interacts with the program while the child process is
191 // running, you can use this flag to prevent this from happening
196 MustHaveApp(wxExecute);
198 long wxExecute(const wxString& command,
199 int flags = wxEXEC_ASYNC,
200 wxPyProcess *process = NULL);
204 %typemap(in,numinputs=0) wxKillError* rc ( wxKillError temp ) { $1 = &temp; }
205 %typemap(argout) wxKillError* rc
208 o = PyInt_FromLong((long) (*$1));
209 #if SWIG_VERSION < 0x010328
210 $result = t_output_helper($result, o);
212 $result = SWIG_Python_AppendOutput($result, o);
216 int wxKill(long pid, wxSignal sig = wxSIGTERM, wxKillError* rc, int flags = wxKILL_NOCHILDREN);
219 //---------------------------------------------------------------------------
221 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
223 //---------------------------------------------------------------------------