在 NSIS 安装程序脚本中,我尝试检查给定的 httpd.conf 文件是否包含以下行:
Include "c:\xxx\yyy.conf"
如果是这样,那么我的安装程序脚本不会将其附加到文件中,否则,它将附加它。
我已经完成了 {LineFind},但不确定这是否真的能实现我想要实现的目标。
从 NSIS 脚本对文本文件执行“grep”的最简单方法是什么?
谢谢!
最佳答案
这里是一个在文件中搜索给定行的示例,使用 LogicLib 来简化语法。一旦找到该行,搜索就会停止。该示例适用于示例脚本本身:
# find.nsi : sample for LineFind from TextFunc.nsh
!include "textfunc.nsh"
!include "logiclib.nsh"
OutFile "find.exe"
!define lookfor `Section` ;will find
;!define lookfor `Sectionn` ;will not find
Var found
Section
StrCpy $found 0
${LineFind} "find.nsi" "/NUL" "1:-1" "GrepFunc"
${if} $found = 1
MessageBox MB_OK "string found"
${else}
MessageBox MB_OK "string NOT found"
${endIf}
SectionEnd
Function GrepFunc
${TrimNewLines} '$R9' $R9
DetailPrint "test for line $R8 `$R9`"
${if} $R9 == "${lookfor}"
StrCpy $found 1 ;set flag
Push "StopLineFind" ;stop find
${else}
Push 0 ;ignore -> continue
${endIf}
FunctionEnd
关于string - 从 NSIS 脚本中查找文件中的字符串模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962645/