Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Command-Line Command from NSIS

Tags:

nsis

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 begin and other similar topics have gone a little over my head.

like image 408
user1457296 Avatar asked Jul 16 '12 18:07

user1457296


People also ask

How do you run NSIS?

NSIS Setup You can use the NSIS Menu and under the Compiler section click Compile NSI scripts to start MakeNSISW. The makensisw.exe in the NSIS installation folder is the actual compiler. It has a graphical front end that explains three ways to load scripts, so it's very easy to use.

How do you compile NSIS?

nsi file by simply right-clicking on it in Explorer and selecting 'compile'. If you want to use MakeNSIS on the command line, the syntax of makensis is: makensis [ option | script.

Does NSIS work on Linux?

Portable CompilerThe NSIS compiler can be compiled for POSIX platforms like Linux and *BSD. Generated installer will still run on Windows only, but this way they can be generated without Windows or WINE.


2 Answers

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)

like image 115
RyanE Avatar answered Oct 09 '22 00:10

RyanE


Try using exec command http://nsis.sourceforge.net/Docs/Chapter4.html:

4.9.1.2 Exec

command

Execute the specified program and continue immediately. Note that the file specified must exist on the target system, not the compiling system. $OUTDIR is used for the working directory. The error flag is set if the process could not be launched. Note, if the command could have spaces, you should put it in quotes to delimit it from parameters. e.g.: Exec '"$INSTDIR\command.exe" parameters'. If you don't put it in quotes it will not work on Windows 9x with or without parameters.

Exec '"$INSTDIR\someprogram.exe"'
Exec '"$INSTDIR\someprogram.exe" some parameters'
like image 21
zenpoy Avatar answered Oct 08 '22 23:10

zenpoy