AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

processing command line parameters

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Mon Jan 23, 2006 8:38 pm    Post subject: processing command line parameters Reply with quote

Since I couldn't find a function that processes command line parameters, I went to write one myself.
Not sure if it's perfect, but it seems to work fine (improvements are always welcome though):
Code:
; process command line parameters
getParams:
   Loop, %0% ; for each parameter
   {
      param := %A_Index%
      ; check for switches
      StringLeft, paramType, param, 1
      If paramType = - ; switch indicator
      {
          ; determine type of switch
          StringMid, switch, param, 2, 1
          ; settings file switch
         If switch = s
         {
             ; access value (= next parameter)
            param = % A_Index + 1
            file_settings := %param%
            MsgBox, settings file:`n%file_settings%
         }
      }
   }
Return
This script checks whether there are any parameters at all, then goes on to check whether a parameter is a switch (i.e. starting with a minus char - this can easily be modified to check for slashes though) and retrieves the accompanying value (in this case, the desired settings file).

Last edited by Ace_NoOne on Mon Feb 12, 2007 9:48 am; edited 1 time in total
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10471

PostPosted: Mon Jan 23, 2006 9:58 pm    Post subject: Reply with quote

You're right, I don't recall seeing any others than yours posted. This kind of processing will definitely be useful.
Back to top
View user's profile Send private message Send e-mail
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Wed Aug 16, 2006 6:24 pm    Post subject: Reply with quote

I shorted the function to its bare bone:
Code:
Loop, %0% {                       ;for each command line parameter
    If (%A_Index% = "/in")        ;check if known command line parameter exists
        param_in := A_Index + 1   ;assign next command line parameter as value
    Else If (%A_Index% = "/log")
        param_log := A_Index + 1
  }

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Mon Feb 12, 2007 9:47 am    Post subject: Reply with quote

toralf wrote:
I shorted the function to its bare bone:
Code:
Loop, %0% {                       ;for each command line parameter
    If (%A_Index% = "/in")        ;check if known command line parameter exists
        param_in := A_Index + 1   ;assign next command line parameter as value
    Else If (%A_Index% = "/log")
        param_log := A_Index + 1
  }
I might be a little late with this, but I just noticed that param_log := A_Index + 1 will just assign a number, not the actual content of the respective variable.
This you will need something like
Code:
param_log := A_Index + 1
param_log := %param_log%

Anyways, I really like your solution, toralf!

PS: I've removed the If 0 > 0 part from my original code; it's redundant, as Loop, %0% does not run if there are no command line parameters.
_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group