CmdExec: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (→Description) |
m (use %comspec% instead of $sysdir\cmd.exe) |
||
Line 8: | Line 8: | ||
== Macro == | == Macro == | ||
<highlight-nsis>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | <highlight-nsis>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Execute a command with cmd.exe | ;; Execute a command with cmd.exe | ||
;; P1 :in: Working directory | ;; P1 :in: Working directory, ignored if "" ($OutDir is used) | ||
;; P2 :in: Command and parameters | ;; P2 :in: Command and parameters | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
!define | !define CmdExec "!insertmacro _CmdExec 0" | ||
!define | !define CmdPause "!insertmacro _CmdExec 1" | ||
!define | !define CmdWait "!insertmacro _CmdExec 2" | ||
!define CmdPauseWait "!insertmacro _CmdExec 3" | !define CmdPauseWait "!insertmacro _CmdExec 3" | ||
!define CmdStay "!insertmacro _CmdExec 4" ; | !define CmdStay "!insertmacro _CmdExec 4" ; Stay in command box after execution | ||
!define CmdStayWait "!insertmacro _CmdExec 5" ; | !define CmdStayWait "!insertmacro _CmdExec 5" ; Stay in command box after execution, and wait for it to exit | ||
!macro _CmdExec _Mode_ _WorkDir_ _CommandAndParams_ ; Mode: 0=nopause/nowait, 1=dospause, 2=execwait, 3=dospause+execwait | |||
!macro _CmdExec _Mode_ _WorkDir_ _CommandAndParams_ | Push $R0 | ||
StrCmp "${_WorkDir_}" "" +3 | ExpandEnvStrings $R0 '%COMSPEC%' | ||
Push $OutDir | StrCmp "${_WorkDir_}" "" +3 | ||
SetOutPath "${_WorkDir_}" | Push $OutDir | ||
!if '${_Mode_}' == '1' | SetOutPath "${_WorkDir_}" | ||
!if '${_Mode_}' == '1' | |||
!else if '${_Mode_}' == '2' | Exec `"$R0" /c "${_CommandAndParams_}" & echo. & echo. & pause` | ||
!else if '${_Mode_}' == '2' | |||
!else if '${_Mode_}' == '3' | ExecWait `"$R0" /c "${_CommandAndParams_}"` | ||
ExecWait `"$ | !else if '${_Mode_}' == '3' | ||
ExecWait `"$R0" /c "${_CommandAndParams_}" & echo. & echo. & pause` | |||
!else if '${_Mode_}' == '4' | !else if '${_Mode_}' == '4' | ||
Exec `"$ | Exec `"$R0" /k "${_CommandAndParams_}"` | ||
!else if '${_Mode_}' == '5' | !else if '${_Mode_}' == '5' | ||
ExecWait `"$ | ExecWait `"$R0" /k "${_CommandAndParams_}"` | ||
!else | !else | ||
Exec `"$ | Exec `"$R0" /c "${_CommandAndParams_}"` | ||
!endif | !endif | ||
StrCmp "${_WorkDir_}" "" + | StrCmp "${_WorkDir_}" "" +3 | ||
Pop $R0 | |||
SetOutPath "$R0" | SetOutPath "$R0" | ||
Pop $R0 | |||
!macroend</highlight-nsis> | !macroend</highlight-nsis> | ||
[[Category:Functions & Macros]] | [[Category:Functions & Macros]] |
Revision as of 02:10, 6 February 2012
Author: Lloigor (talk, contrib) |
Description
Use cmd.exe to execute a command and its parameters, with working dir, optional dospause, stayinprompt 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, ignored if "" ($OutDir is used) ;; P2 :in: Command and parameters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; !define CmdExec "!insertmacro _CmdExec 0" !define CmdPause "!insertmacro _CmdExec 1" !define CmdWait "!insertmacro _CmdExec 2" !define CmdPauseWait "!insertmacro _CmdExec 3" !define CmdStay "!insertmacro _CmdExec 4" ; Stay in command box after execution !define CmdStayWait "!insertmacro _CmdExec 5" ; Stay in command box after execution, and wait for it to exit !macro _CmdExec _Mode_ _WorkDir_ _CommandAndParams_ ; Mode: 0=nopause/nowait, 1=dospause, 2=execwait, 3=dospause+execwait Push $R0 ExpandEnvStrings $R0 '%COMSPEC%' StrCmp "${_WorkDir_}" "" +3 Push $OutDir SetOutPath "${_WorkDir_}" !if '${_Mode_}' == '1' Exec `"$R0" /c "${_CommandAndParams_}" & echo. & echo. & pause` !else if '${_Mode_}' == '2' ExecWait `"$R0" /c "${_CommandAndParams_}"` !else if '${_Mode_}' == '3' ExecWait `"$R0" /c "${_CommandAndParams_}" & echo. & echo. & pause` !else if '${_Mode_}' == '4' Exec `"$R0" /k "${_CommandAndParams_}"` !else if '${_Mode_}' == '5' ExecWait `"$R0" /k "${_CommandAndParams_}"` !else Exec `"$R0" /c "${_CommandAndParams_}"` !endif StrCmp "${_WorkDir_}" "" +3 Pop $R0 SetOutPath "$R0" Pop $R0 !macroend