Execute Command-Line Command from NSIS

前端 未结 3 1222
梦如初夏
梦如初夏 2021-02-07 08:28

I\'m creating my first NSI script and I\'m just wondering if I can execute a command-line command from NSIS or should I just execute a batch file? I don\'t really know where to

3条回答
  •  无人及你
    2021-02-07 08:56

    I would recommend taking a look at the nsExec plugin. I just recently had a situation where I needed to ping a server from inside an NSIS script, and the following code worked perfectly for me.

    nsExec::Exec '"C:\Windows\System32\PING.EXE" $URL'
    

    The benefit of using nsExec is that it executes the command without making a dos box pop up on your screen. The return value is pushed onto the stack, and there are a couple different ways that you can access the output of the program as well (if any exists).

    There isn't a whole lot of information about the plugin on the NSIS website that I could find, but the following link should get you started in the right direction:

    http://nsis.sourceforge.net/Docs/nsExec/nsExec.txt

    Edit:

    I noticed you asked specifically about a COPY command which is an internal DOS command, meaning that you won't be able to execute it like I did with ping. I may be mistaken but you shouldn't need to use any outside programs to carry out basic commands like this. You should be able to replicate most of the internal commands using NSIS commands.

    For Example to copy a file (or multiple files) use the NSIS command: CopyFiles

    The NSIS Scripting Reference is your friend :) (So is ctrl+f)

提交回复
热议问题