View Single Post
Old 7th August 2020, 13:20   #1
1marc1
Junior Member
 
Join Date: Apr 2019
Posts: 5
Issue with executing a command

Hi Team,

For a number of evenings I have been struggling with the following.

One of the things my installer does is it installs a Ruby gem. Prior to the installation, I want to remove all versions of the gem so that I can be sure only the specific version is running on the user's system.

To accomplish this, I have been trying lots of different things, but none are working.

When uninstalling manually, all I need to do is run:
code:
C:\Ruby25-x64\bin\gem.cmd uninstall MyGem -a -I -x


The issue is that some users may be running Ruby version 2.6.x, others are on 2.7.x. Therefore the path to the `gem.cmd` changes.

I have created a macro that determines the correct path on the user's system to the `gem.cmd` file. This macro sets the value of the GEMCMD variable. This works fine.

The problem comes when I try to instruct NSIS to execute the command. I have tried a number of different things, but neither of them uninstalls MyGem.

Please see the code snippet below. The bottom four lines show my latest examples of things that I tried. The first of those works, but has the path hard-coded. The other three don't work.


code:
; The following sets the value of the GEMCMD variable.
!insertmacro DetermineGem

; Message to verify that the gem command is correctly assigned to the variable.
MessageBox MB_OK "Gem command is: $GEMCMD"

ExpandEnvStrings $0 %COMSPEC%
; good: nsExec::ExecToStack '"$0" /C C:\Ruby25-x64\bin\gem.cmd uninstall MyGem -a -I -x'
; bad : nsExec::ExecToStack '"$0" /C $GEMCMD uninstall MyGem -a -I -x'
; bad : nsExec::ExecToStack '"$0" /C "$GEMCMD" uninstall MyGem -a -I -x'
; bad : ExecWait '"$0" "/C" "$GEMCMD" "uninstall" "MyGem" "-a" "-I" "-x"' $0



Thank you in advance for any advice on this.

Marc.
1marc1 is offline   Reply With Quote