Archive: Reading from a file at compile time


Reading from a file at compile time
This may be very simple thing but I couldn't find it anywhere.

I want to read some values from a file (config.json) into some variables when I compile my nsis script.
How can I possibly do that?

Another question is I want to hit a url without opening any browser window, I tried 'execshell ' it did the task but opened the url in default browser window which I dont want. what other options do I have?

Thanks in advance.


use !system or !execute to run an (NSIS) exe, which reads the file using normal runtime commands and writes to an .nsh file that contains !define Foo "string 1" !define Bar "string 2". Then just !include that .nsh file in your real .nsi.


Thanks. So I must use another exe. That will work. But I wish there was some other way , I really dont want to use an extra exe.


You could even compile a second nsi file into that exe during compilation, to automate everything.


Use the nsJSON plug-in in a small script (ParseJSON.nsi) which will read the json file and output an nsh file (with !defines):

OutFile ParseJSON.exe
SilentInstall silent
RequestExecutionLevel user

Section
FileOpen $R0 $EXEDIR\Const.nsh w
nsJSON:: ...
FileWrite $R0 '!define ....'
FileClose $R0
SectionEnd
Then you can put this in your main script:
!system `"${NSISDIR}\makensis.exe" ParseJSON.nsi`
!system `ParseJSON.exe`
!system `del ParseJSON.exe`
!include ParseJSON.nsh
Personally I just use an nsh file containing !defines for compile time configuration for basic installers.

Stu