Shah
Shah

Reputation: 553

Running batch script with two msiexec commands causes finishing script just after finishing first command

I am trying to run batch script from jenkins job which has two msiexec commands one for uninstallation and other for installation.
This script is on github so jenkins job clone the repo and then run the script

Jenkins job start execution of second msiexec (installation) command but it ends immediately.If i open Job console i can see message "Process leaked file descriptors." and job status : Success


If i run The same script through cmd without jenkins it is working fine.

setlocal enabledelayedexpansion 
IF EXIST "directory path" (
msiexec /uninstall {Product ID} /qb
)
pushd \\shared drive
IF EXIST "directory path" (
msiexec /i "path to exefile" /qb
popd
exit 0
)
ELSE (
ECHO Setup Not Found in current
exit 0
)

Upvotes: 0

Views: 974

Answers (1)

Mofi
Mofi

Reputation: 49127

The keyword ELSE must be on same line as ) of TRUE branch of IF condition separated from ) by a space character. The ELSE on a separate line is interpreted like name of a console application to run.

if exist "directory path" (
    %SystemRoot%\System32\msiexec.exe /uninstall {Product ID} /qb
)
pushd "\\ComputerName\ShareName\"
if exist "directory path" (
    %SystemRoot%\System32\msiexec.exe /i "path to exefile" /qb
) else (
    echo Setup not found in %CD%.
)
popd
exit /B 0

Hint: For debugging a batch file run it from within a command prompt window and not with double clicking on it after removing or commenting all lines containing echo off. And don't use EXIT without /B as this results always in exiting entire command process and not only in exiting just processing of current batch file. Debugging a batch file in a command prompt window becomes difficult if the batch file contains EXIT without /B and this command is really executed on running the batch file because error messages output during running the batch file can't be seen in this case.

Upvotes: 0

Related Questions