Skip to content
⌘ NSIS Forum Archive

Return value from !system

8 posts

Mike C#

Return value from !system

Hi all,

LTL, FTP here. I'm trying to figure out how to get hold of the return value from a system command executed at compile-time, using the !system command.

I've checked out the documentation at http://nsis.sourceforge.net/Docs/Chapter5.html#system but I'm being a bit dense about figuring out the 'symbol' bit, and there isn't a code example.

The format is, as the doc says:

!system command symbol
What exactly is 'symbol' and how do I define it, and get the value from it?

Any help appreciated! Thanks.
aerDNA#
With e.g. !system "some.exe" = 0 script will only compile if some.exe returns 0. But afaik you can't get the exit code and use it for flow control if that's what you want.
Mike C#
Originally Posted by aerDNA View Post
With e.g. !system "some.exe" = 0 script will only compile if some.exe returns 0. But afaik you can't get the exit code and use it for flow control if that's what you want.
OK, thanks for that! Just tried it out, and it works fine for me. I can go with simply failing the script compilation for now.

Many thanks for your help!
aerDNA#
Originally Posted by aerDNA View Post
afaik you can't get the exit code
For the record, there is way: you could run a batch file that runs the exe, checks errorlevel and outputs the result in a text file; then you get it with !searchparse.
Afrow UK#
!system command symbol
!if ${symbol} = 0
...
!else
...
!endif
It essentially does a !define symbol [return_value], thus ${symbol} can then be used in your script at compile time.

Only works with NSIS 3.0+.

Stu
Mike C#
Originally Posted by Afrow UK View Post
Only works with NSIS 3.0+.
Aha! That's what I was missing - we're using 2.46 here.

Your code example is exactly how I interpreted the documentation. It's good to know that I wasn't being dense after all (on this occasion...).
Anders#
Originally Posted by aerDNA View Post
I didn't know there were changes to !system. Nice.
This and !makensis was added mostly to help people sign the uninstaller, it allows you to do some %temp% cleanup before aborting with a error message...