nsis - 如何在不覆盖寄存器的情况下为 NSIS exe 生成的日志条目添加当前日期和时间的前缀?
问题描述
我想在 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 等,但这不会编译。
解决方案
$year
是一个自定义变量:
Var year
Section
${GetTime} ... $year ...
FileWrite ...
SectionEnd
如果您需要保留旧数据(通常需要在辅助宏中执行此操作),另一种选择是保存/恢复旧数据:
Section
Push $0
Push $1
Push ...
${GetTime} ... $0 $1 ...
FileWrite ...
Pop ...
Pop $1
Pop $0
SectionEnd
推荐阅读
- firebase-cloud-messaging - android,如何从推送通知点击打开谷歌播放
- python - Django/Python 为 AppConfiguring 的 makemigrations 反馈 ImproperlyConfigured
- cmd - 无法连接到服务器端口#:连接被拒绝
- amazon-web-services - AWS IAM - 您能否根据资源创建时间限制对 AWS 资源的访问?
- javascript - 有没有办法使用空手道框架比较两组评估为真假值的日期?
- java - 无法读取 OWL 公理
- python - 如何在html上解析和显示markdown内容的序列图和流程图?
- javascript - ES模块系统不保证模块单例吗?
- postgresql - 用于多个准备好的语句的 JDBC 批处理
- python - Python SQLalchemy 1.4 ORM:我需要导入什么才能使用 in_()?