如何在NSIS中以静默方式将命令输出重定向到文件?

时间:2017-11-16 06:05:00

标签: nsis

在GUI模式下,CopyFilesDelete等命令将其数据输出到GUI(可能正在使用DetailPrint),并且它们在NSIS上可用function论坛将该数据(在section末尾)复制到文件中。

查询:

  1. 如果安装程序以静默方式运行,如何将相同的数据(以非静默模式定向到GUI)获取到文件?

  2. 在GUI模式下,因为我在function的帮助下通过DetailPrint将自定义日志定向到日志文件,以便按顺序接收所有日志。这里的问题是从自定义日志中删除换行符。可以DetailPrint删除它。我该怎样避免这个?

    示例:

    DetailPrint "This is a custom log1"
    DetailPrint "$\r$\nThis is a custom log2"
    /* 
      Dumped these logs using function mentioned above
      Output in logs(with no line breaks):
      This is a custom log1
      This is a custom log2
    
      Required output:
      This is a custom log1
    
      This is a custom log2
    */
    

1 个答案:

答案 0 :(得分:1)

您的第二个查询已解决。

!include "MUI2.nsh"
section
StrCpy $0 "$EXEDIR\install.log"
Push $0
    DetailPrint "This is a custom log1"
    DetailPrint "This is a custom log2"
    Call DumpLog
sectionend

;!define LVM_GETITEMCOUNT 0x1004
!define LVM_GETITEMTEXT 0x102D

Function DumpLog
  Exch $5
  Push $0
  Push $1
  Push $2
  Push $3
  Push $4
  Push $6

  FindWindow $0 "#32770" "" $HWNDPARENT
  GetDlgItem $0 $0 1016
  StrCmp $0 0 exit
  FileOpen $5 $5 "w"
  StrCmp $5 "" exit
    SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
    System::Alloc ${NSIS_MAX_STRLEN}
    Pop $3
    StrCpy $2 0
    System::Call "*(i, i, i, i, i, i, i, i, i) i \
      (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
    loop: StrCmp $2 $6 done
      System::Call "User32::SendMessageA(i, i, i, i) i \
        ($0, ${LVM_GETITEMTEXT}, $2, r1)"
      System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
      FileWrite $5 "$4$\r$\n"
      FileWrite $5  "$\r$\n"
      IntOp $2 $2 + 1
      Goto loop
    done:
      FileClose $5
      System::Free $1
      System::Free $3
  exit:
    Pop $6
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Pop $0
    Exch $5
FunctionEnd

您的示例代码适合我。它根据您的要求提供输出。 不要将"$\r$\n"放在Detailprint中。像我一样在DumpLog函数中添加FileWrite $5 "$\r$\n"。这样您就不必在每个细节打印中放置$\r$\n

相关问题