!echo "$%MY_VAR%"

Prints out

$%MY_VAR% (...\installer.nsi:46)

So the variable isn't replaced at all. Is this a bug? I'm a bit stumped here. How am I supposed to test if the variable exists? So far I thought I could use

!if "$%MY_VAR%" = ""

but that's not going to work if there is no replacement at all. The logical conclusion would be to use this:

!if "$%MY_VAR%" = "$%MY_VAR%"

Am I doing it wrong?

有帮助吗?

解决方案

!if x = y is actually a number test, you need to use == to test strings.

You need to trick the compiler to get this to work:

; NSIS 2+
!define DOLLAR $
!if "$%foo%" == "${DOLLAR}%foo%"
!echo "%foo% not set"
!endif

; NSIS 3+
!if "$%foo%" == "${U+24}%foo%"
!echo "%foo% not set"
!endif

其他提示

I just did a quick test (NSIS 3.0a0 and Unicode NSIS 2.46.5, both on Windows 7 x64) and I have no problem getting the $%ENV_VAR% replaced. Here's how I'm testing it:

!if "$%MY_VAR%" != ""
    !echo "MY_VAR is set"
!else
    !warning "MY_VAR not set"
!endif

I take it you already double checked your environmental variable was really saved

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top