Sign in to follow this  
Followers 0
ProgAndy

Extended CmdLine-Handling

3 posts in this topic

#1 ·  Posted (edited)

Have you ever wanted to have a better handling of parameters in the form /parameter="A value", -parameter value, +parameter:"value ""inline"" quotes", ... ?

These UDFs help you to accomplish the task in a simple and elegant way, creating a 2D-Array that combines each parameter with its value.

#include-once
; #FUNCTION# ====================================================================================================================
; Name...........: _CmdLine_GetClean
; Description ...: Strips leading AutoIt-parameters from $CMDLINERAW
; Syntax.........: _CmdLine_GetClean()
; Parameters ....:
; Return values .: $CMDLINERAW without AutoIt-parameters
; Author ........: ProgAndy
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _CmdLine_ParseParameters
; Description ...: Parses commandline parameters
; Syntax.........: _CmdLine_ParseParameters($sParameters [, $fSpaceForValue = True])
; Parameters ....: $sParameters     - string with parameters in commandline form
;                  $fSpaceForValue  - [optional] Allow space between a parameter and its value. (default: True)
;                  |If this parameter is false, a value must be separated via :, = or | from the argumentname.
;                  +Also, parameters are not required to be prefixed with --, +, -, /, | but it is allowed.
;                  |If it is true, also a space is allowed to separate argument and value, but all
;                  +parameters must be prefixed with --, +, -, / or |.
;                  $fUnescapeQuotes - [optional] Specify whether quotes in quote values are unescaped (default: false)
; Return values .: Success      - 2D-Array in the following format:
;                  |    $array[$i][0] : prefix
;                  |    $array[$i][1] : Parameter without prefix
;                  |    $array[$i][2] : Value with quotation marks (only if value has quotaion marks)
;                  |    $array[$i][3] : Value without quotation marks
;                  Failure      - 0 and @error <> 0
; Author ........: ProgAndy
; Modified.......:
; Remarks .......: Quotes inside of double quotes must be doubled to get them through: /param="Value with ""some"" quotes"
;                  This can be automatically reversed by setting $fUnescapeQuotes to True.
;                  Then $array[$i][3] will contain 'Value with "some" quotes'.
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _CmdLine_Split
; Description ...: Separates a filename and the given parameters
; Syntax.........: _CmdLine_Split($sCommand)
; Parameters ....: $sCommand     - string with command (filename + parameters)
; Return values .: Success - Array with 2 values.
;                  |[0] - the found filename.
;                  |[1] - the parameters
;                  Error  - 0 (No filename was found)
; Author ........: ProgAndy
; ===============================================================================================================================

CmdLine.au3

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites



Excellent! I pass command line arguments to my AutoIt scripts all the time and this makes it so easy. Shame on everyone for not recognizing this sooner. You rock!


Progress lies not in enhancing what is, but in advancing towards what will be. - Kahlil Gibran

Share this post


Link to post
Share on other sites

Not recognizing this sooner? Shame on you for not seeing :)

Mines based on a similar idea, but I worked with the default AutoIt $CmdLine array, and instead of using a 2D array, the user calls a function called CmdLine() with a string value of the parameter, and it returns it's argument if it has one, true if it is there but without an argument, and false otherwise.

Nice work though ProgAndy :)

Mat

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0