Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 14th November 2018, 14:04   #1
green_biri
Junior Member
 
Join Date: Nov 2018
Posts: 4
Weird behaviour occurring when executing cmd file with ExecWait/nsExec/Exec

Hi everyone, I'm trying to execute a cmd file on my NSIS script.

The cmd file contains only the following instructions to setup NodeJS:

code:

call npm install -g appium
call npm install -g appium-doctor



In order to run the script, I've tried to use ExecWait, nsExec::Exec and Exec. Currently I'm using ExecWait, since every command is behaving the same way. Here is the way I'm calling the script:

code:

ExecWait '"$sysdir\cmd.exe" /C if 1==1 "$INSTDIR\npm_config.cmd"'



The problem is, the instructions in the cmd file will only be executed the second time I run the installer.

To further explain:

- I have the ExecWait in a separate section.

- If I run the installer for the first time and choose the section, the cmd does not execute (cmd window just blinks and error code is 1). If I run the installer a second time and choose the section, the instructions will execute without any issue (cmd window opens and executes everything like expected).

- If I don't choose the section on the first time the installer is ran, obviously it won't execute my cmd. However, if I reopen the installer and then select the section, it will execute the cmd correctly.

So, to resume, I need to open and reopen my installer in order for the cmd instructions to be executed correctly.

What could be causing this behaviour? How can I debug the issue?
green_biri is offline   Reply With Quote
Old 14th November 2018, 15:00   #2
green_biri
Junior Member
 
Join Date: Nov 2018
Posts: 4
Apparently I cannot edit my post : (

I've discovered that reopening the installer will not work.

This is my current workaround:

- Open installer
- Install other section
- Close installer and reopen
- Select section where cmd is called
- Cmd works
green_biri is offline   Reply With Quote
Old 14th November 2018, 16:36   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,183
Whatever is going on is not NSIS, must be something in the batch.

Change /C to /K or add "pause" to the end of your batch-file so you can see the output of your batch...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th November 2018, 17:02   #4
green_biri
Junior Member
 
Join Date: Nov 2018
Posts: 4
Hi Anders,

Thank you for the suggestion! Apparently I get the generic error "npm is not a recognized command/file", which means that the installer does not have the correct environment variables after running the NodeJS setup in unattended mode (i'm installing JDK and NodeJS before running the cmd).

So I guess the question now is: How do I re-read/reload the environment variables during the installation? Is there any way to do it?

Thank you once again.
green_biri is offline   Reply With Quote
Old 14th November 2018, 17:40   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,183
The easy solution is to just prepend the batch file with "set path=%path%;$nodeinstallpath".

There is a undocumented Windows function you can call to update the in-process environment but I don't remember its name off the top of my head.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th November 2018, 10:57   #6
green_biri
Junior Member
 
Join Date: Nov 2018
Posts: 4
Thanks Anders!

I believe the function you are mentioning is this one (found it here):

code:
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PATH", R0).r0'


After adding it to my script, I was able to fix the problem. Thank you once again for helping me reach the solution!
green_biri is offline   Reply With Quote
Old 15th November 2018, 12:09   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,183
That one is documented, I was thinking of RegenerateUserEnvironment.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump