]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/utilsexc.cpp
70e7e5a1edf69d70e39e7cdd0ed2d85d030502b0
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/utilsexec.cpp
3 // Purpose: Various utilities
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
21 #include "wx/process.h"
23 #include "wx/os2/private.h"
49 // this message is sent when the process we're waiting for terminates
50 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
56 // structure describing the process we're being waiting for
62 // cout << "Closing thread: " << endl;
63 DosExit(EXIT_PROCESS
, 0);
66 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
67 RESULTCODES vResultCodes
;
69 ULONG ulExitCode
; // the exit code of the process
70 bool bState
; // set to false when the process finishes
73 static ULONG
wxExecuteThread(wxExecuteData
* pData
)
78 // cout << "Executing thread: " << endl;
80 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
84 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
88 wxLogLastError(wxT("DosWaitChild"));
94 // window procedure of a hidden window which is created just to receive
95 // the notification message when a process exits
96 MRESULT APIENTRY
wxExecuteWindowCbk( HWND hWnd
,
98 MPARAM
WXUNUSED(wParam
),
101 if (ulMessage
== wxWM_PROC_TERMINATED
)
103 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
107 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
108 ,(int)pData
->vResultCodes
.codeResult
114 // we're executing synchronously, tell the waiting thread
115 // that the process finished
120 // asynchronous execution - we should do the clean up
123 ::WinDestroyWindow(hWnd
); // we don't need it any more
128 long wxExecute( const wxString
& rCommand
,
131 const wxExecuteEnv
*env
)
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
222 , const wxExecuteEnv
*env
227 while (*ppArgv
!= NULL
)
229 wxString
sArg((wxChar
*)(*ppArgv
++));
232 sCommand
<< sArg
.c_str() << ' ';
234 sCommand
.RemoveLast();
235 return wxExecute( sCommand
242 bool wxGetFullHostName( wxChar
* zBuf
, int nMaxSize
)
244 return wxGetHostName( zBuf
, nMaxSize
);