1. 程式人生 > >C++以阻塞的方式呼叫外部exe程式,等待其執行結束

C++以阻塞的方式呼叫外部exe程式,等待其執行結束

        SHELLEXECUTEINFO ShExecInfo = {0};
        ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
        ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
        ShExecInfo.hwnd = NULL;
        ShExecInfo.lpVerb = L"open";//多種類別有 "explorer" "print" 等
        ShExecInfo.lpFile = EXE_FILE;//exe 路徑    
        ShExecInfo.lpParameters = pbuffer;//引數
        ShExecInfo.lpDirectory = NULL;
        ShExecInfo.nShow = SW_HIDE;//
        ShExecInfo.hInstApp = NULL;
        ShellExecuteEx(&ShExecInfo);

        WaitForSingleObject(ShExecInfo.hProcess, INFINITE);//等待完成   第二個引數是超時時間(毫秒)超時後返回超時程式碼