2016-01-23 1 views
1

J'ai plusieurs fichiers batch que j'exécute depuis Inno Setup. J'utilise ShellExecuteEx() pour exécuter des fichiers batch:Récupère le code de sortie du fichier batch dans Inno Setup en utilisant ShellExecuteEx

function ShellExecuteWait(const Verb, Filename, Params, WorkingDir: string; const ShowCmd: integer; const Timeout: cardinal; var ExitCode: DWORD): boolean; 
var 
    ExecInfo: TShellExecuteInfo; 
begin 
    Result := false; 

    ExecInfo.cbSize := SizeOf(ExecInfo); 
    ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS; 
    ExecInfo.Wnd := 0; 
    ExecInfo.lpVerb := Verb; 
    ExecInfo.lpFile := Filename; 
    ExecInfo.lpParameters := Params; 
    ExecInfo.lpDirectory := WorkingDir; 
    ExecInfo.nShow := ShowCmd; 

    if ShellExecuteEx(ExecInfo) then 
    begin 
    if WaitForSingleObject(ExecInfo.hProcess, Timeout) = WAIT_TIMEOUT then 
    begin 
     TerminateProcess(ExecInfo.hProcess, WAIT_TIMEOUT); 
    end else begin 
    end; 
    GetExitCodeProcess(ExecInfo.hProcess, ExitCode); 
    Result := (ExitCode = ERROR_SUCCESS); 
    end else begin 
    ExitCode := GetLastError(); 
    end; 
end; 

if (not ShellExecuteWait('', 
         Command, 
         Params, 
         ExpandConstant('{tmp}'), 
         SW_SHOW, 
         Timeout, 
         ResultCode)) then... 

Mais peu importe ce que j'essaie, je ne peux pas obtenir le code de sortie du fichier de commandes dans ResultCode (je reçois toujours en arrière 0).

En recherchant ce problème, j'ai lu que le lot ne doit PAS utiliser exit /b NN. J'ai donc supprimé le commutateur /b, mais je reçois toujours 0.

Que dois-je faire pour obtenir le code de sortie à partir d'un fichier de commandes?

Dennis

+0

Quelle que soit la raison pour laquelle vous utilisez ShellExecuteEx et non pas ShellExec (http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_shellexec)? –

Répondre

0

J'ai trouvé le problème. La commande pour appeler le fichier de commandes inclut un canal à travers un autre programme, donc le code de résultat que je récupère vient en fait du programme par lequel la sortie du script est canalisée.