- NSIS Discussion
 - GetOptions question
 
Archive: GetOptions question
zeeh3
8th December 2006 17:33 UTC
GetOptions question
Hi, I noticed that GetOptions macro is giving me different results depending on the presence os spaces on path name. For example, c:\path gives me 'result' and c:\pa th gives me '"result"' (with "s). I got errors depending on which path I use command line params with NSIS.
zeeh3
9th December 2006 09:18 UTC
Well, $CMDLINE is the culprit. The second part of params does not have quotations marks if path name does not have spaces. Is this a bug?
Instructor
9th December 2006 10:20 UTC
Name "Output"
OutFile "Output.exe"
!include "FileFunc.nsh"
!insertmacro GetParameters
!insertmacro GetOptions
Section
        ${GetParameters} $0
        ${GetOptions} '$0' '/LOG=' $1
        MessageBox MB_OK '$$0={$0}$\n$$1={$1}'
SectionEnd
     
    
    
      zeeh3
      9th December 2006 16:53 UTC
      Pardon me, Instructor! I meant GetParameters and not GetOptions macro, sorry!
      
      As I said in my last post, the problem is with $CMDLINE and not with the macros.
     
    
    
      zeeh3
      9th December 2006 17:07 UTC
      Test this sript in 2 different directories, one like 'c:\test' and another like 'c:\test 2'. You will see that one result has quotations marks and the other does not have.
     
    
    
      Instructor
      9th December 2006 18:50 UTC
      What the contents of the $CMDLINE?
     
    
    
      zeeh3
      10th December 2006 10:00 UTC
      Let me explain in another way. The contents of $CMDLINE (and of GetParameters macro too) will differ depending on the folder name. If there are spaces in path name where the installer is (like c:\test 2\installer.exe), when I drag and drop a file (for example test.txt) in the same path over installer.exe $CMDLINE will be '"C:\test 2\commandline.exe" "C:\test 2\test.txt"' and GetParameters macro '"C:\test 2\test.txt"'. If I change the folder's name to c:\test and drag and drop test.txt again over installer.exe the $CMDLINE will be '"C:\test\commandline.exe" C:\test\test.txt' and GetParameters macro 'C:\test\test.txt' (without quotations marks).
     
    
    
      Instructor
      10th December 2006 10:36 UTC
      '"C:\test 2\commandline.exe" "C:\test 2\test.txt"' -> '"C:\test 2\test.txt"'
      '"C:\test\commandline.exe" C:\test\test.txt' -> 'C:\test\test.txt'
      It is correct GetParameters simply cut first part that contain exe name.
     
    
    
      zeeh3
      10th December 2006 11:25 UTC
      I know that. I have put an if statement to overcome these extra quotations marks depending on spaces in the path. I just wonder why $CMDLINE is giving me theses different results.
     
    
    
      demiller9
      10th December 2006 16:04 UTC
      The system (OS) adds the quotes; $CMDLINE is just showing you what it gets.
      
      I did a couple little tests to try to prove this, first by using Notepad (drag a file onto it, and then check its CMDLINE by using Process explorer), and also by dragging files into a cmd window. Both experiments show quotes being added when the pathnames include spaces.
      
      Don
     
    
    
      zeeh3
      10th December 2006 17:10 UTC
      Thanks for the info, demiller9. I have fixed my script to deal with this strange OS behavior.