Sign in to follow this  
Followers 0
kor

how to allow my script to accept switches?

3 posts in this topic

I'm not sure how to accomplish this or even what commands I should be looking at. I am wanting to pass switches to my script when executing it, and have my script interrupt those switches and do different things depending on what the switches are.

IE:

script.exe /e

How do I tell the script to accept that /e, and how do I get the script to use that /e to do something?

Basically what I want is that switch to be a drive letter, so if the switch is /e, then it would be Drive E:, but if the switch is /F, then it would be drive F:

Share this post


Link to post
Share on other sites



Type in in SciTe: cmdlineselect and then hit space.

Now you get an example for this.

Or use help with keyword "Command Line Parameters".


Best Regards BugFix  

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

My code:

Global $drive = ""

ReadParameters()

MsgBox(0, "Drive is", $drive)

Func ReadParameters()
    For $i = 1 to $CmdLine[0]
        Select
            Case $CmdLine[$i] = "/d"
                If $i == $CmdLine[0] Then Error()
                If StringLeft($cmdline[$i+1], 1) == "/" Then
                    Error()
                Else
                    $drive = StringStripWS($CmdLine[$i + 1], 3)
                EndIf
        EndSelect
    Next
        If $drive == "" Then
            Error()
        EndIf
EndFunc

Func Error()
    MsgBox(0, "Error", "Invalid Parameters")
    Exit
EndFunc

Simplified from: http://motersho.com/blog/index.php/2009/10/20/autoit-command-line-parameters-a-new-approach/

Edited by kor

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