Sign in to follow this  
Followers 0
MilesAhead

command line switch parsing?

6 posts in this topic

Anyone know if there are functions for command line switch parsing?

Stuff like

myprog.exe --option=whatever or /option=whatever

I couldn't find anything in the help other than $CmdLine

I know I could roll my own but I thought somebody may have invented this

wheel already. Always nice to use debugged code. :)

Share this post


Link to post
Share on other sites



Anyone know if there are functions for command line switch parsing?

Stuff like

myprog.exe --option=whatever or /option=whatever

I couldn't find anything in the help other than $CmdLine

I know I could roll my own but I thought somebody may have invented this

wheel already. Always nice to use debugged code. :)

It's been done to death. Try out the forum search function.

>_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Maybe, i can help you :)

file.exe -h Msgbox: Hello!

file.exe -u Msgbox: Bye!

file.exe /h Msgbox: Hello!

file.exe /u Msgbox: Bye!

#cs ----------------------------------------------------------------------------
written by "DCCD" fredj 
:                Email:  info.dccd@gmail.com
:                Website: www.libyalinux.com
#ce ----------------------------------------------------------------------------
If $cmdline[0] > 0 Then
    Switch $cmdline[1]
        Case "-h", "/h"
            MsgBox(0, "using -h", "Hello!")
        Case "-u", "/u"
            MsgBox(4096, "using -u", "Bye!")
        Case Else
            ConsoleWrite(" - - - Help - - - " & @crlf)
            ConsoleWrite("  -h : msgbox says Hello!" & @crlf)
            ConsoleWrite("  -u : msgbox says Bye!" & @crlf)
            ConsoleWrite(" - - - - - - - - " & @crlf)
        EndSwitch
    EndIf
Exit
Edited by DCCD

Share this post


Link to post
Share on other sites

It's been done to death. Try out the forum search function.

:)

Yeah I did try it out. You don't know what to search for until

you find it though. That's why I ask while I'm still searching.

Wasted a lot of time with the word "parse" but got into

GetOpt back door through google somehow.

Anyway, I went with the quick and dirty

if start of string is /x= then ... cuz I'm lazy. >_<

Share this post


Link to post
Share on other sites

Maybe, i can help you :)

Thanks for the reply. That's a viable alternative. Nice

and simple. The little utility I'm doing, I have a lot

of params that will likely be crammed in a shortcut

Target line so I think it's good to have them glued

together with the /x= thingy. >_<

I like both solutions since neither has a lot to go wrong. :idiot:

Share this post


Link to post
Share on other sites

Case "-x", "/x
!!!
Nope, I did it the sloppy way with a big For loop.

The more restrictive the method of assigning the

options the better. Less to go wrong. I could have

just used _Get_Opt or whatever it is... but then if it

broke I'd have to figure it out!!

With '/x=' options if something doesn't work, most likely

it's a matter of which WinApi makes you double quote

stuff with a space and which doesn't. Seems to be

no consistent pattern. Trial and error still rules!! :)

Besides, I already pasted a bunch of If blocks in my For loop >_<

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