如何从NSIS exe生成的日志条目以当前日期和时间作为前缀而不覆盖寄存器?

问题描述 投票:0回答:1

我想在运行NSIS(Nullsoft).exe程序的过程中,在输入日志的每一行的开头都写入时间戳。

看来,调用GetTime函数的唯一有效模式是:$ {GetTime}“”“ L” $ 0 $ 1 $ 2 $ 3 $ 4 $ 5 $ 6

这将覆盖正在调用的.nsh文件中的寄存器($ 0,$ 1等)。有没有办法防止这种情况?

例如:

global_defines.nsh包含以下内容:

!macro WriteLog text
...
  FileWrite $mylogfile '${text}'
  ${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
  FileWrite $mylogfile "$2-$1-$0 $4:$5:$6 '${text}'"
...

并且正在调用的.nsh文件包含如下内容:

StrCpy $1 'run_this_script'
!insertmacro WriteLog "About to run: $1"
ExecDos::exec /TOWINDOW $1
pop $0
!insertmacro WriteLog "script run returned $0"

这将把$ 1设置为宏中设置的月份值。

单独发布:https://stackoverflow.com/a/19622151/6388369使用$ year等显示,但无法编译。

nsis
1个回答
0
投票

$year是自定义变量:

Var year

Section
${GetTime} ... $year ...
FileWrite ...
SectionEnd

另一种替代方法是,如果需要保留/保存旧数据(通常需要在帮助程序宏中进行此操作,请执行以下操作:]

Section
Push $0
Push $1
Push ...
${GetTime} ... $0 $1 ...
FileWrite ...
Pop ...
Pop $1
Pop $0
SectionEnd
© www.soinside.com 2019 - 2024. All rights reserved.