Search the Community
Showing results for tags '$cmdline parse'.
-
Would be nice to have a function that can simplify $cmdline parsing and function a bit like like iniRead() does. $cmdline = ' -debug /param "c:"' $debug = cmdline('debug',False) Func cmdline($switchtofind, $default = '') EndFunc Found a function by Prog@ndy that would be nice to unitize for this but there is a bug: can't read when parameter ends with " Any idea how to fix? #include <Array.au3> $CMDString = '/a:"value" -big="this -test:1"23 is & $#@ _ your life" -installpath "c:" -test=th_3 -tte -äß$=/ätest/h.b' $ResultArray = _ParseCMDLine($CMDString) _ArrayDisplay($ResultArray) ;=============================================================================== ; ; Function Name: _ParseCMDLine($CMDString) ; Description:: Parses a CMD-String to Parameters with Values ; Parameter(s): $CMDString -> String to parse ; Requirement(s): ? ; Return Value(s): Error: 0 and @error = StringRegExp-Error ; Success: 2 Dimensional Array: ; $array[$i][0] : Parameter including value ; $array[$i][1] : Parameter ; $array[$i][2] : Value with quotation marks (only if value has quotaion marks) ; $array[$i][3] : Value without quotation marks ; Author(s): Prog@ndy ; ; Basis: http://regexlib.com/REDetails.aspx?regexp_id=1220 ;=============================================================================== ; Func _ParseCMDLine($CMDString) Local $y, $j, $i, $entry Local $x = StringRegExp($CMDString,'(?:s*)(?<=[-|/])(?<name>[^s-|/:|]*)(?:(?:[:|](?:("(?<value1>.*?)(?<!)")|(?<value>S*)))|w*?)',4) If @error Then Return SetError(@error,0,0) Local $ResultArray[UBound($x)][4] For $i = 0 To UBound($x)-1 $entry = $x[$i] For $y = 0 To UBound($entry)-1 $j = $y If $y > 3 Then $j = 3 $ResultArray[$i][$j] = $entry[$y] Next Next Return $ResultArray EndFunc