Skip to content
⌘ NSIS Forum Archive

Running batch file from NSIS

6 posts

zron#

Running batch file from NSIS

i am using:

ExpandEnvStrings $0 %COMSPEC%
ExecWait '"$0" /C "c:\path\to\batch.cmd" "quoted param" normalparam "c:\last param"'


To run a batch file from NSIS.
What are my options to know if the batch.cmd failed or succeed?
Is there an way to get CMD errorlevel parameter after the batch call in NSIS?

Thanks
zron#
is seems that when i m running
ExecWait '"$INSTDIR\someprogram.exe"' $0

with a batch file the value $0 is always == 1
Anders#
ExecWait reports the process (cmd.exe for batch files) exit code.

Batch files have broken exit code handling, to fix it, as the LAST line in your batchfile use
@%COMSPEC% /C exit %errorlevel% >nul
See also:
Have you ever written a batch file that is more of a “application” than a script? Of course you made sure ERRORLEVEL is set correctly so when your batch file is a part of a larger scrip…
zron#
Thanks a lot!!!
i will try it, though i found a work around - writing the errorlevel to a file and NSIS read the result.