CmdExec: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Execute a command with cmd.exe, with optional dospause and execwait.)
 
m (cosmetic issue)
Line 13: Line 13:
;;  P2 :in: Command and parameters  
;;  P2 :in: Command and parameters  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
!define CmdExec "!insertmacro _CmdExec 0"  
!define CmdExec "!insertmacro _CmdExec 0"     ; nopause/nowait
!define CmdPause "!insertmacro _CmdExec 1"  
!define CmdPause "!insertmacro _CmdExec 1"     ; dospause
!define CmdWait "!insertmacro _CmdExec 2"  
!define CmdWait "!insertmacro _CmdExec 2"     ; execwait
!define CmdPauseWait "!insertmacro _CmdExec 3"  
!define CmdPauseWait "!insertmacro _CmdExec 3" ; dospause+execwait
!macro _CmdExec _Mode_ _WorkDir_ _CommandAndParams_ ; Mode: 0=nopause/nowait, 1=dospause, 2=execwait, 3=dospause+execwait
!macro _CmdExec _Mode_ _WorkDir_ _CommandAndParams_
   StrCmp "${_WorkDir_}" "" +3  
   StrCmp "${_WorkDir_}" "" +3  
       Push $OutDir  
       Push $OutDir  

Revision as of 16:56, 4 February 2012

Author: Lloigor (talk, contrib)


Description

Execute a command with cmd.exe, with optional dospause and execwait.

Example

${CmdPause} `$ParentFolder` `"d:\tools\free_upx\upx.exe" -v --brute $FileNames`

Macro

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;  Execute a command with cmd.exe 
;;  P1 :in: Working directory (""=$outdir) 
;;  P2 :in: Command and parameters 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
!define CmdExec "!insertmacro _CmdExec 0"      ; nopause/nowait
!define CmdPause "!insertmacro _CmdExec 1"     ; dospause
!define CmdWait "!insertmacro _CmdExec 2"      ; execwait
!define CmdPauseWait "!insertmacro _CmdExec 3" ; dospause+execwait
!macro _CmdExec _Mode_ _WorkDir_ _CommandAndParams_
   StrCmp "${_WorkDir_}" "" +3 
      Push $OutDir 
      SetOutPath "${_WorkDir_}" 
   !if '${_Mode_}' == '1' 
      Exec `"$SYSDIR\cmd.exe" /c "${_CommandAndParams_}" & echo. & echo. & pause` 
   !else if '${_Mode_}' == '2' 
      ExecWait `"$SYSDIR\cmd.exe" /c "${_CommandAndParams_}"` 
   !else if '${_Mode_}' == '3' 
      ExecWait `"$SYSDIR\cmd.exe" /c "${_CommandAndParams_}" & echo. & echo. & pause` 
   !else 
      Exec `"$SYSDIR\cmd.exe" /c "${_CommandAndParams_}"` 
   !endif 
   StrCmp "${_WorkDir_}" "" +4 
      Exch $R0 
      SetOutPath "$R0" 
      Pop $R0 
!macroend