]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/utilsexc.cpp
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"
23 #include "wx/process.h"
25 #include "wx/os2/private.h"
51 // this message is sent when the process we're waiting for terminates
52 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
58 // structure describing the process we're being waiting for
64 // cout << "Closing thread: " << endl;
65 DosExit(EXIT_PROCESS
, 0);
68 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to [not used]
69 RESULTCODES vResultCodes
;
71 ULONG ulExitCode
; // the exit code of the process
72 bool bState
; // set to false when the process finishes
75 static ULONG
wxExecuteThread(wxExecuteData
* pData
)
80 // cout << "Executing thread: " << endl;
82 ulRc
= ::DosWaitChild( DCWA_PROCESSTREE
86 ,pData
->vResultCodes
.codeTerminate
// process PID to look at
90 wxLogLastError(wxT("DosWaitChild"));
96 // window procedure of a hidden window which is created just to receive
97 // the notification message when a process exits
98 MRESULT APIENTRY
wxExecuteWindowCbk( HWND hWnd
,
100 MPARAM
WXUNUSED(wParam
),
103 if (ulMessage
== wxWM_PROC_TERMINATED
)
105 wxExecuteData
* pData
= (wxExecuteData
*)lParam
;
109 pData
->pHandler
->OnTerminate( (int)pData
->vResultCodes
.codeTerminate
110 ,(int)pData
->vResultCodes
.codeResult
116 // we're executing synchronously, tell the waiting thread
117 // that the process finished
122 // asynchronous execution - we should do the clean up
125 ::WinDestroyWindow(hWnd
); // we don't need it any more
130 long wxExecute( const wxString
& rCommand
,
134 if (rCommand
.empty())
136 // cout << "empty command in wxExecute." << endl;
140 // create the process
141 UCHAR vLoadError
[CCHMAXPATH
] = {0};
142 RESULTCODES vResultCodes
= {0};
149 if (flags
& wxEXEC_SYNC
)
150 ulExecFlag
= EXEC_SYNC
;
152 ulExecFlag
= EXEC_ASYNCRESULT
;
154 rc
= ::DosExecPgm( (PCHAR
)vLoadError
160 ,(PSZ
)rCommand
.c_str()
164 wxLogSysError(_("Execution of command '%s' failed with error: %ul"), rCommand
.c_str(), rc
);
167 // cout << "Executing: " << rCommand.c_str() << endl;
169 wxExecuteData
* pData
= new wxExecuteData
;
171 pData
->vResultCodes
= vResultCodes
;
172 pData
->hWnd
= NULLHANDLE
;
173 pData
->bState
= (flags
& wxEXEC_SYNC
) != 0;
174 if (flags
& wxEXEC_SYNC
)
176 wxASSERT_MSG(!pHandler
, wxT("wxProcess param ignored for sync execution"));
177 pData
->pHandler
= NULL
;
181 // may be NULL or not
182 pData
->pHandler
= pHandler
;
185 rc
= ::DosCreateThread( &vTID
186 ,(PFNTHREAD
)&wxExecuteThread
188 ,CREATE_READY
|STACK_SPARSE
193 wxLogLastError(wxT("CreateThread in wxExecute"));
196 // the process still started up successfully...
197 return vResultCodes
.codeTerminate
;
199 if (!(flags
& wxEXEC_SYNC
))
202 // warning: don't exit your app unless you actively
203 // kill and cleanup you child processes
204 // Maybe detach the process here???
205 // If cmd.exe need to pass DETACH to detach the process here
206 return vResultCodes
.codeTerminate
;
209 // waiting until command executed
210 ::DosWaitThread(&vTID
, DCWW_WAIT
);
212 ULONG ulExitCode
= pData
->vResultCodes
.codeResult
;
215 // return the exit code
216 return (long)ulExitCode
;
222 , wxProcess
* pHandler
227 while (*ppArgv
!= NULL
)
229 wxString
sArg((wxChar
*)(*ppArgv
++));
232 sCommand
<< sArg
.c_str() << ' ';
234 sCommand
.RemoveLast();
235 return wxExecute( sCommand
241 bool wxGetFullHostName( wxChar
* zBuf
,
247 unsigned long ulLevel
= 0;
248 unsigned char* zBuffer
= NULL
;
249 unsigned long ulBuffer
= 256;
250 unsigned long* pulTotalAvail
= NULL
;
252 NetBios32GetInfo( (const unsigned char*)zServer
253 ,(const unsigned char*)zComputer
259 strncpy(zBuf
, zComputer
, nMaxSize
);
260 zBuf
[nMaxSize
] = _T('\0');
262 wxUnusedVar(nMaxSize
);
263 strcpy((char*)zBuf
, "noname");
265 return *zBuf
? true : false;