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
Old 7th August 2020, 15:53   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,296
Change nsExec::ExecToStack to DetailPrint and post the output

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 8th August 2020, 12:41   #3
1marc1
Junior Member
 
Join Date: Apr 2019
Posts: 5
Anders,

I had been looking at the DetailPrint output, but the command was too long to fit in the window. I have now implemented the DumpLog function and reviewed things in the log file it creates. In there I found that the value of $GEMCMD ends in a newline...

I have now implemented the Trim function and things are now working they way I want.

Thanks again for putting me on the right track.

Marc.
1marc1 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