]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/utilsexc.cpp
c50a311691f10f3c4bc540e3b5bda7ff5fc4dc97
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/utilsexec.cpp
3 // Purpose: Various utilities
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/process.h"
24 #include "wx/os2/private.h"
50 // this message is sent when the process we're waiting for terminates
51 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
57 // structure describing the process we're being waiting for
63 // cout << "Closing thread: " << endl;
64 DosExit(EXIT_PROCESS
, 0);
67 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
68 RESULTCODES vResultCodes
;
70 ULONG ulExitCode
; // the exit code of the process
71 bool bState
; // set to false when the process finishes
74 static ULONG
wxExecuteThread(wxExecuteData
* pData
)
79 // cout << "Executing thread: " << endl;
81 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
85 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
89 wxLogLastError(wxT("DosWaitChild"));
95 // window procedure of a hidden window which is created just to receive
96 // the notification message when a process exits
97 MRESULT APIENTRY
wxExecuteWindowCbk( HWND hWnd
,
99 MPARAM
WXUNUSED(wParam
),
102 if (ulMessage
== wxWM_PROC_TERMINATED
)
104 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
108 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
109 ,(int)pData
->vResultCodes
.codeResult
115 // we're executing synchronously, tell the waiting thread
116 // that the process finished
121 // asynchronous execution - we should do the clean up
124 ::WinDestroyWindow(hWnd
); // we don't need it any more
129 long wxExecute( const wxString
& rCommand
,
133 if (rCommand
.empty())
135 // cout << "empty command in wxExecute." << endl;
139 // create the process
140 UCHAR vLoadError
[CCHMAXPATH
] = {0};
141 RESULTCODES vResultCodes
= {0};
148 if (flags
& wxEXEC_SYNC
)
149 ulExecFlag
= EXEC_SYNC
;
151 ulExecFlag
= EXEC_ASYNCRESULT
;
153 rc
= ::DosExecPgm( (PCHAR
)vLoadError
163 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
166 // cout << "Executing: " << rCommand.c_str() << endl;
168 wxExecuteData
* pData
= new wxExecuteData
;
170 pData
->vResultCodes
= vResultCodes
;
171 pData
->hWnd
= NULLHANDLE
;
172 pData
->bState
= (flags
& wxEXEC_SYNC
) != 0;
173 if (flags
& wxEXEC_SYNC
)
175 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
176 pData
->pHandler
= NULL
;
180 // may be NULL or not
181 pData
->pHandler
= pHandler
;
184 rc
= ::DosCreateThread( &vTID
185 ,(PFNTHREAD
)&wxExecuteThread
187 ,CREATE_READY
|STACK_SPARSE
192 wxLogLastError(wxT("CreateThread in wxExecute"));
195 // the process still started up successfully...
196 return vResultCodes
.codeTerminate
;
198 if (!(flags
& wxEXEC_SYNC
))
201 // warning: don't exit your app unless you actively
202 // kill and cleanup you child processes
203 // Maybe detach the process here???
204 // If cmd.exe need to pass DETACH to detach the process here
205 return vResultCodes
.codeTerminate
;
208 // waiting until command executed
209 ::DosWaitThread(&vTID
, DCWW_WAIT
);
211 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
214 // return the exit code
215 return (long)ulExitCode
;
221 , wxProcess
* pHandler
226 while (*ppArgv
!= NULL
)
228 wxString
sArg((wxChar
*)(*ppArgv
++));
231 sCommand
<< sArg
.c_str() << ' ';
233 sCommand
.RemoveLast();
234 return wxExecute( sCommand
240 bool wxGetFullHostName( wxChar
* zBuf
, int nMaxSize
)
242 return wxGetHostName( zBuf
, nMaxSize
);