 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Ace_NoOne
Joined: 10 Oct 2005 Posts: 333 Location: Germany
|
Posted: Mon Jan 23, 2006 8:38 pm Post subject: processing command line parameters |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10471
|
Posted: Mon Jan 23, 2006 9:58 pm Post subject: |
|
|
| You're right, I don't recall seeing any others than yours posted. This kind of processing will definitely be useful. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Wed Aug 16, 2006 6:24 pm Post subject: |
|
|
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 |
|
 |
Ace_NoOne
Joined: 10 Oct 2005 Posts: 333 Location: Germany
|
Posted: Mon Feb 12, 2007 9:47 am Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|