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);//等待完成   第二个参数是超时时间(毫秒)超时后返回超时代码    


你可能感兴趣的:(C/C++)