congahonga
19th March 2009 10:39 UTC
Annotation
I a lot of DOS comands, so i don't want to make for every command a batch-file with "pause", and later switch back to exec without batch-files. So, i search for a trick to make every ExecWait command output "visible" with a small extra command...
Comperio
19th March 2009 15:37 UTC
There may be another way, but if it where me, I might consider something like this:
Make your calling methods into a macro and place it in it's own header file (*.NSH).
Then, when you want to switch, you only need to rewrite your macro. (Your main script code could remain the same; you'd just switch header files.)
Examples of a macro:
; Dos window
!macro ExecMyCommand CustomExec command param
Exec 'cmd.exe /c "${command}" ${param}'
!macroend
; no window
!macro ExecMyCommand CustomExec command param
nsExec::ExectoLog 'cmd.exe /c "${command}" ${param}'
!macroend
Then in your main script:
!include myheader.nsh
...
!insertmacro ExecMyCommand "myfile.bat" "/d /a=p"
You could also tweak your macro to have both methods and insert the proper one based on another define. like:
!ifdef debug
; define old macro
!else
; define new macro
!endif
AaronLS
21st March 2009 04:12 UTC
I'm not sure what your goal is, but I use ExecToStack for running command line/console mode tools during installation. This allows you access to everything that appeared in the console, as well as the return code. You could display this in a message box or log it to a file.
congahonga
23rd March 2009 10:40 UTC
Very easy way !
I found another VERY EASY way !
Instead of
ExecWait "setsu.exe $3 -s StandardUser -m KWO -d operational"
which doesn't prompt, even if an error occurs.
I use
ExecWait "cmd /c pause | setsu.exe $3 -s StandardUser -m KWO -d operational"
(setsu.exe is a special command as a file, that i use)
The trick is, that "cmd /c" means for the shell: execute only ONE command, then close.
"pause | setsu.exe" is a piped command (so it's in fact one command, even if it looks like two commands)
This is a trick to add a pause to every Shell-Command.
Attention: is not "<command> | pause", it's vice versa like above
I try to combine this trick with dependend compiling, so you can set one compiler directive and the output stops with pause (while developing) and you can cancel this function with one compiler directive !
When i found it out, i post it here for YOU ALL!
by the way: look in wikipedia for "cmd" there a quit a lot of very nice parameters, to expend shell functionalities. Perhaps you will need that !
congahonga
23rd March 2009 12:32 UTC
That's it finally
Now you can switch between debug-mode with a break, and release mode without a break !
I didn't usw compiler-directives, I use an normal variable called DEBUG, that makes it.
Please reply my post, if you like my "dirty trick", because i want to find out, if i found out a good trick, or a bad one... :-)
------------------------------------------------------------
Name "Test"
OutFile "Test.exe"
!include LogicLib.nsh
VAR cmd_prefix
VAR DEBUG
Page instfiles
Section
# 1 for debug-mode, 0 for release without breaks
push 1
pop $DEBUG
${If} $DEBUG == 0
StrCpy $cmd_prefix "cmd /c"
${else}
StrCpy $cmd_prefix "cmd /c pause |"
${endif}
ExecWait "$cmd_prefix echo 1.Command simulated with echo"
ExecWait "$cmd_prefix echo 2.Command simulated with echo"
SectionEnd