如何在不覆盖寄存器的情况下为从 NSIS exe 生成的日志条目添加当前日期和时间前缀?

How to prefix log entries generated from NSIS exe with current date and time without overwriting registers?

我想在 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" [=10=]      
  FileWrite $mylogfile "--[=10=] :: '${text}'"
...

调用的 .nsh 文件包含如下内容:

StrCpy  'run_this_script'
!insertmacro WriteLog "About to run: "
ExecDos::exec /TOWINDOW 
pop [=11=]
!insertmacro WriteLog "script run returned [=11=]"

这导致 $1 被设置为在宏中设置的月份值。

单独发帖: 显示使用 $year 等,但这不会编译。

$year 是自定义变量:

Var year

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

另一个选择是 save/restore 如果您需要保留旧数据(您通常需要在辅助宏中这样做):

Section
Push [=11=]
Push 
Push ...
${GetTime} ... [=11=]  ...
FileWrite ...
Pop ...
Pop 
Pop [=11=]
SectionEnd