NSIS编译时命令,用于计算txt文件并将结果设置为全局变量。

huangapple go评论52阅读模式
英文:

NSIS compile-time command to calculate txt file and set result as global variable

问题

我是一个NSIS初学者,我需要一些帮助。我有一个包含许多行数字的txt文件。我想使用一个编译时命令(如!system或其他命令)来读取每一行的数字,将它们相加,并将总和转换为一个可以在脚本中使用的全局变量。有人能提出一个实现这个目标的好方法吗?非常感谢您的帮助!

我写了:

**`!system 'for /f "tokens=1" %a in (filesize.txt) do set /a sum+=%a'`**

这个命令成功运行了,我可以从编译日志中看到结果已经计算出来了。如何将命令行输出的计算结果转换为可以全局使用的变量?
英文:

I am a NSIS beginner and I need some help. I have a txt file which contains many rows of numbers. I want to use a compile-time command (such as !system or other) to read each line of numbers, add them together, and convert the sum into a global variable that can be used in the script. Can anyone suggest a good method to achieve this? Thank you very much in advance!

I wrote

!system 'for /f "tokens=1" %a in (filesize.txt) do set /a sum+=%a'

which ran successfully and I can see from the compile log that the result has been calculated. How can I convert the calculated result from the command line output to a variable that can be used globally?

答案1

得分: 0

以下是翻译后的内容:

必须将标准输出重定向到一个文件,然后您可以使用 !include 命令:

!tempfile STDOUT
!system 'echo StrCpy $0 1234 >> "${STDOUT}"'
!include "${STDOUT}"
!delfile "${STDOUT}"
!undef STDOUT

如果命令较为复杂,您可能需要创建一个批处理文件:

!tempfile BAT
!appendfile "${BAT}.bat" 'echo foo >> %1$\n'
!appendfile "${BAT}.bat" 'dir bar >> %1$\n'
!tempfile STDOUT
!system '"${BAT}.bat" "${STDOUT}"'
!delfile "${BAT}.bat"
!undef BAT
!include "${STDOUT}"
!delfile "${STDOUT}"
!undef STDOUT
英文:

You must redirect stdout to a file you can !include:

!tempfile STDOUT
!system 'echo StrCpy $0 1234 >> "${STDOUT}"'
!include "${STDOUT}"
!delfile "${STDOUT}"
!undef STDOUT

If the command is complex you might have to make a batch file:

!tempfile BAT
!appendfile "${BAT}.bat" 'echo foo >> %1$\n'
!appendfile "${BAT}.bat" 'dir bar >> %1$\n'
!tempfile STDOUT
!system '"${BAT}.bat" "${STDOUT}"'
!delfile "${BAT}.bat"
!undef BAT
!include "${STDOUT}"
!delfile "${STDOUT}"
!undef STDOUT

huangapple
  • 本文由 发表于 2023年4月6日 23:03:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951018.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定