2012-06-05 29 views
10

Cómo obtener el valor de retorno de un exe que se llama mediante la función shellexecute.cómo obtener el valor de retorno de un ejecutable llamado por ShellExecute

ShellExecute(NULL, NULL, TEXT (".\\dpinstx86.exe"), NULL, NULL, SW_SHOWNORMAL); 

En el ejemplo anterior quiero el valor de retorno de "dpinstx86.exe".

+1

Creo que lo que quiere decir con "valor de retorno" es la salida del CMD, que esta pregunta se refiere a: http://stackoverflow.com/questions/469152/using-shellexecuteex-and-capturing-standard-in -out-err. – Ben

Respuesta

19

En su lugar, utilice ShellExecuteEx para obtener el identificador del proceso y GetExitCodeProcess para obtener el código de salida.

SHELLEXECUTEINFO ShExecInfo = {0}; 
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); 
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; 
ShExecInfo.hwnd = NULL; 
ShExecInfo.lpVerb = NULL; 
ShExecInfo.lpFile = "c:\\MyProgram.exe";   
ShExecInfo.lpParameters = ""; 
ShExecInfo.lpDirectory = NULL; 
ShExecInfo.nShow = SW_SHOW; 
ShExecInfo.hInstApp = NULL; 
ShellExecuteEx(&ShExecInfo); 
WaitForSingleObject(ShExecInfo.hProcess,INFINITE); 
+1

No olvides * esperar * en el mango. –

+0

cualquier ejemplo será genial ... – 2vision2

+1

http://www.codeproject.com/Articles/1842/A-newbie-s-elementary-guide-to-spawning-processes ... y llame a GetExitCodeProcess() con hProcess miembro de SHELLEXECUTEINFO. – kol

Cuestiones relacionadas