I'm trying to compare a string with a variable with have exactly the same value and isn't working.
The flow is:
1. Open a file that has just one line of Node.Js version;
2. Read the line and save into $NODE_VERSION
3. Close file
4. Check if $NODE_VERSION
is equal "v8.11.3" -- and this always returns false.
I had already:
1. Create another variable and set in hardcoded the same values for both and compare.
2. Compare the $NODE_VERSION with the string "v8.11.3"
3. Compare "1" = "1" and works.
4. Use If/EndIf
5. Use StrCmp
Var /GLOBAL NODE_VERSION<br/>
Function .onInit<br/>
ExecWait "node --version > C:\Windows\nodeversion.txt"<br/>
ClearErrors<br/>
FileOpen $0 "C:\Windows\nodeversion.txt" r<br/>
IfErrors done<br/>
FileRead $0 $NODE_VERSION<br/>
FileClose $0<br/>
StrCmp $NODE_VERSION "v8.11.3" 0 nobla<br/>
Messagebox MB_OK "not true, or maybe"<br/>
nobla:<br/>
Messagebox MB_OK "not true"<br/>
Messagebox MB_OK $NODE_VERSION<br/>
${If} $NODE_VERSION == "v8.11.3"<br/>
Call uninstallNode<br/>
Goto FinishInit<br/>
${EndIf}<br/>
I want to get into a true statement
FileRead
includes newline-characters in the returned string and you must remove them when you are looking for a exact string match.
!include "LogicLib.nsh"
!include "StrFunc.nsh"
${StrTrimNewLines} ; Tell StrFunc.nsh to define this function for us
Section
FileOpen $0 "$windir\nodeversion.txt" r
FileRead $0 $1
${StrTrimNewLines} $1 $1
FileClose $0
MessageBox mb_ok "Line 1=|$1|"
${If} "v8.11.3" == "$1"
; ...
${EndIf}
SectionEnd
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.