Problema
Come si esegue un eseguibile con parametri passati su di esso da un programma C++?
Soluzione
Usa ShellExecuteEx
e SHELLEXECUTEINFO
Problema
Come si ottiene il valore restituito da esso?
Soluzione
Usa GetExitCodeProcess
e exitCode
cose essenziali da sapere
Se si vuole aspettare fino al processo, che sta gestendo da exe esterno, è finito quindi necessario utilizzare WaitForSingleObject
bool ClassName::ExecuteExternalExeFileNGetReturnValue(Parameter ...)
{
DWORD exitCode = 0;
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = _T("open");
ShExecInfo.lpFile = _T("XXX.exe");
ShExecInfo.lpParameters = strParameter.c_str();
ShExecInfo.lpDirectory = strEXEPath.c_str();
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
if(WaitForSingleObject(ShExecInfo.hProcess,INFINITE) == 0){
GetExitCodeProcess(ShExecInfo.hProcess, &exitCode);
if(exitCode != 0){
return false;
}else{
return true;
}
}else{
return false;
}
}
Reference to know more detail
fonte
2017-02-07 02:09:23
come gestisci para metri con spazi in loro? (ad esempio "arg 1", "arg 2") – Bill