简体   繁体   English

NSIS-尝试比较两个字符串时出错

[英]NSIS - Error trying to compare two strings

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; 1.打开一个只有一行Node.Js版本的文件;
2. Read the line and save into $NODE_VERSION 2.阅读该行并保存到$NODE_VERSION
3. Close file 3.关闭档案
4. Check if $NODE_VERSION is equal "v8.11.3" -- and this always returns false. 4.检查$NODE_VERSION是否等于“ v8.11.3”-且始终返回false。

I had already: 我已经:
1. Create another variable and set in hardcoded the same values for both and compare. 1.创建另一个变量,并为每个变量设置相同的硬编码值并进行比较。
2. Compare the $NODE_VERSION with the string "v8.11.3" 2.比较$ NODE_VERSION与字符串“ v8.11.3”
3. Compare "1" = "1" and works. 3.比较“ 1” =“ 1”并起作用。
4. Use If/EndIf 4.使用If / EndIf
5. Use StrCmp 5.使用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. FileRead在返回的字符串中包含换行符,并且在查找完全匹配的字符串时必须将其删除。

!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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM