Exec vs ExecWait vs ExecShell vs nsExec::Exec vs nsExec::ExecToLog vs nsExec::ExecToStack vs ExecDos vs ExeCmd
Asked Answered
E

2

59

Can I know what are the differences between each Exec, ExecWait, ExecShell, nsExec::Exec, nsExec::ExecToLog, nsExec::ExecToStack, ExecDos and ExecCmd, as in when to use which?

I 've posted the various execute calls I know. I am trying to make a comprehensive list, so that it helps future visitors..

  1. Exec: Plainly execute the called string, be it some application, console or file.

  2. ExecWait: Executes like Exec but waits till the process exits.

  3. ExecShell: What is it for?

  4. nsExec::Exec: Just like Exec or ExecWait but only for command prompt and that too without opening the console window. I am unsure if it waits for process to exit. Does nsExec::Exec wait for child process to exit?

  5. nsExec::ExecToLog: The documentation says ExecToLog is similar to plain nsExec but it outputs to log window. What does that mean, what is a log window?

  6. nsExec::ExecToStack: The documentation says ExecToStack is similar to plain nsExec but it pushes output to stack. I get that.

  7. ExecDos: Same as nsExec::ExecToStack but it additionally (Is it not?)

    a. takes string parameter that serves as stdin for running application.

    b. works in both sync/async mode.

    c. it works out of section - for .onInit check outs.

  8. ExecCmd: Same as ExecDos but it doesn't require these

    ExpandEnvStrings $3 %COMSPEC% 
    ExecDos::exec  /C 
    

    parts. Am I correct?

Essive answered 29/7, 2012 at 11:15 Comment(4)
You may include Timeout::ExecTimeout too, for those who need to kill child process if it takes too long to complete.Thorlay
@FranciscoR Feel free to edit the question and add it (along with its purpose). I'm not so knowledgeable about the one you mentioned.Essive
Realistically, the explanations for what each command should do belong in an answer, not in the question itself. "Am I correct?" = bad StackOverflow question. I'm tempted to move those bits to an answer, but there's already an answer that moving would invalidate.Banquet
@MooingDuck the problem is if I ask a question like that it might very well get closed since the question would look too broad and loaded and without research effort. I wanted to show some effort put by myself, at the same time quite complete with explanation for all the execute commands in one place. Of course someone can put them all as one answer, that will be good too.Essive
A
49

1) 2) 3)

Exec and ExecWait use CreateProcess internally and can only start programs and batch files.

ExecShell uses ShellExecute which means that it can also launch any registered filetype (.txt .chm etc) and URLs. It should also be used if the program you are starting needs to elevate with UAC.

4)

nsExec redirects stdout so a console window is not visible when the child process executes. And yes, it waits.

5)

The log window on the instfiles page.

7)

Yes, both ExecDos and ExecCmd are more advanced versions of nsExec.

8)

Correct

Animator answered 29/7, 2012 at 14:56 Comment(0)
S
4

ExecWait waits and thus can return stuff! docs.

ExecShell is also able to hide the output window. docs

ExecCmd is considered outdated and superseded by ExecDos. both are extra plugins for NSIS that are not shipped by default. docs

Sumach answered 6/2, 2015 at 12:1 Comment(3)
You say ExecShell is able to hide the output window. I've been trying to run a batch file without opening a command window but I can't do it. Neither SW_HIDE nor SW_MINIMIZE seem to have any effect.Ninurta
Whow.. Sorry. It's been a while since I dealt with this. I suppose calling a batch file will ALWAYS show a command window. No matter how you call it. That's what a batch file does: run stuff in a command window.Sumach
I've discovered you can run a silent batch file using nsExec::ExecNinurta

© 2022 - 2024 — McMap. All rights reserved.