miraz.zaidi
20th March 2013 07:21 UTC
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.
MSG
20th March 2013 07:43 UTC
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.
miraz.zaidi
20th March 2013 07:58 UTC
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.
MSG
20th March 2013 12:14 UTC
You could even compile a second nsi file into that exe during compilation, to automate everything.
Afrow UK
20th March 2013 13:01 UTC
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