- NSIS Discussion
- Difference between Exec and nsExec
Archive: Difference between Exec and nsExec
mwiseman
9th November 2004 19:44 UTC
Difference between Exec and nsExec
Hello,
I'm trying to run an executable using nsExec. The run always ends in an error that indicates an executable-related error.
nsExec::ExecToLog '"myapp.exe"'
I can run the same executable using Exec without a problem.
Exec '"myapp.exe"'
Thinking that the environment may be the issue, I've tried:
nsExec::ExecToLog '<path_to_cmd.exe> /C "myapp.exe"'
to no avail. This problem seems to point to differences in how nsExec and Exec work but I don't know what they are. Any ideas?
Thanks,
Mike
flizebogen
9th November 2004 20:15 UTC
nsexec was written for command line apps. With nsexec::ExecToLog you can capture the outpu of the app and display it in the result window.
As far as i know it doesn't support live output as used by programs like rar.
mwiseman
9th November 2004 20:40 UTC
myapp.exe is a command line app:
c:\>myapp.exe
Writes to cmd.exe window and terminates.
Afrow UK
9th November 2004 21:51 UTC
Something like this should work:
!define LogFile "$INSTDIR\myapp_dump.txt"
Push $R0
ReadEnvStr $R0 COMSPEC
nsExec::Exec '$R0 /C "$INSTDIR\myapp.exe" > "${LogFile}"'
FileOpen $R0 "${LogFile}" r
LoopRead:
ClearErrors
FileRead $R0 $R1
IfErrors LoopDone
Push $R1
Call TrimNewLines
Pop $R1
DetailPrint $R1
Goto LoopRead
LoopDone:
FileClose $R0
Pop $R0
SetDetailsPrint none
Delete "${LogFile}"
SetDetailsPrint both
That would be another method of capturing the output.
Note that nsExec::Exec will run your application and hide it completely from the user (so the user will not see a command-prompt window.)
-Stu
mwiseman
10th November 2004 16:18 UTC
Thanks for the script but this doesn't really answer my question. I'm not looking for more error output from the nsExec run. The 'nsExec::ExecToLog' does write the errors to the result window. My question is: why would *any* command line program run to completion using:
Exec '"myapp.exe"'
but fail using:
nsExec::ExecToLog '"myapp.exe"'
I'll be more specific now: the app I'm trying to run is Microsoft's Baseline Security Analyzer utility: mbsacli.exe. The error I get seem to be network-related - 'no computer were found'.
Afrow UK
10th November 2004 17:48 UTC
Well, as nsExec doesn't execute your program through COMSPEC then perhaps that's why it is failing. Maybe you have to run it through COMSPEC for it to work?
-Stu
Takhir
10th November 2004 18:10 UTC
Windows MS DOS (console) window is a bit more complex then a process with stdin and stdout only. Simple console applications work fine with nsExec, but some apps require more - terminal emulation or something else (like telnet does). This may be a reason, Exec creates full MS DOS console window, but nsExec simply redirects IO to pipes. You can also try ExecWait with SW_HIDE.
Comm@nder21
12th January 2005 14:51 UTC
You can also try ExecWait with SW_HIDE.
does execwait support window state parameters like SW_HIDE ?
from the nsis docs:
command [user_var(exit code)]
as i need to run a cmd-program in a loop, i need to get the installer wait until it has finished, but also to execute it in the backround without popping up the shell window everytime.
does nsExec::Exec do this, or is it possible to use SW_HIDE with ExecWait?
Takhir
12th January 2005 16:51 UTC
Yes, you are right, I probably had in mind ExecShell. IMHO one of DOS-exec plug-ins is a good decision in your situation.
kichik
13th January 2005 20:23 UTC
It always complains about being unable to create a scan object for me. Can you attach a complete example for which you get the error you're talking about?