]>
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" 
  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
, 
 132                 const wxExecuteEnv 
*env
) 
 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
 
 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
 
 223 , const wxExecuteEnv 
*env
 
 228     while (*ppArgv 
!= NULL
) 
 230         wxString                    
sArg((wxChar
*)(*ppArgv
++)); 
 233         sCommand 
<< sArg
.c_str() << ' '; 
 235     sCommand
.RemoveLast(); 
 236     return wxExecute( sCommand
 
 243 bool wxGetFullHostName( wxChar
* zBuf
, int nMaxSize
) 
 245     return wxGetHostName( zBuf
, nMaxSize 
);