Jump to content

Parse command-line arguments: Difference between revisions

added Autohotkey
(Added zkl)
(added Autohotkey)
Line 2:
 
[[Command-line arguments]] can be quite complicated, as in "nc -v -n -z -w 1 192.168.1.2 1-1000". Many languages provide a library (getopt or GetOpt) to parse the raw command line options in an intelligent way.
 
=={{header|AutoHotkey}}==
For AutoHotkey v1.1+
<lang AutoHotkey>;Get Arguments as an array
if 0 > 0
{
argc=%0%
args:=[]
Loop, %argc%
args.Insert(%A_Index%)
}
else
{
;if got no arguments, run self with arguments
Run,%a_scriptFullpath% -i Lib\* -c files.c --verbose -o files.o --Optimze
ExitApp
}
 
;Parse arguments
i:=0, msg:=""
while( i++ < argc ) {
c:=SubStr(args[i],1,1)
if c in -,/ ; List all switch chars
{
if ( SubStr(args[i],1,2) == "--" ) ; if "--" is used like "--verbose"
msg:=msg args[i] "`t:`tTrue (Boolean)`n" ; parse as boolean
else
msg:=msg args[i] "`t:`t" args[++i] "`n"
}
else
msg:=msg args[i] "`t:`t(normal)`n"
}
 
MsgBox % "Parsed Arguments :`n" msg</lang>
'''Output (MsgBox):'''
<pre>Parsed Arguments :
-i : Lib\*
-c : files.c
--verbose : True (Boolean)
-o : files.o
--Optimze : True (Boolean)</pre>
 
=={{header|Bracmat}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.