web123456

c++ start process waiting for process exit

void startupExe(const std::wstring& paras) { STARTUPINFO startupInfo; PROCESS_INFORMATION procInfo; memset(&startupInfo, 0, sizeof(startupInfo)); memset(&procInfo, 0, sizeof(procInfo)); //commandLine wchar_t commandLine[16]; memset(&commandLine, 0, sizeof(commandLine)); wcscpy_s(commandLine, paras.c_str()); if (CreateProcess( desktopPath.c_str(), commandLine, //My paras = L" /s", here note the space in front of /s nullptr, nullptr, false, CREATE_SUSPENDED, nullptr, nullptr, &startupInfo, &procInfo) != 0) { ResumeThread(); //Wake up the thread WaitForSingleObject(, INFINITE);//Waiting for the process to end, time: unlimited //Close the thread/process CloseHandle(); CloseHandle(); //output success } else { //rescue //output fail } }