Sign in to follow this  
Followers 0
davezub

$CmdLine - Command Line

4 posts in this topic

I've only been using AutoIt for two days and it is a wonderful product. I use Winbatch but AutoIt is quicly winning my heart and mind.

I'm writing a utility that takes 4 commandline parms, however, two are optional. The problem I'm having is testing to see if a commandline is empty/not exist.

I test to see if I have a least two commandline options:

If $CmdLine[0] < 2 .........

However I can't test $CmdLine[3]

If $CmdLine[3] = "".......

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

I realize that $CmdLine is a constant but can't think of a way to test it.

Program "CLOption 1 Req" "CLOption 2 Req" "CLOption 3 Opt" "CLOption 4 Opt"

Thanks.....

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here you go:

If NOT $CmdLine[0] Then
  ;No parameters have been specified
ElseIf $CmdLine[0] = 2 Then
  ;Two parameters have been specified
ElseIf $CmdLine[0] > 2 Then
  ;More than two parameters have been specified
   If $CmdLine[3] = "" Then
     ;Peform action(s) here...
   EndIf
EndIf
Edited by SlimShady

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I use:

For $i = 1 To $CmdLine[0]
    Select
        Case $CmdLine[$i] = "-config"
            $bRunConfig = 1
        Case $CmdLine[$i] = "-runonce"
            $bRunOnce   = 1
    EndSelect
Next

That way it goes through all the arguments and sets variables and such if the commands are given.

You could tweek this to check arguments 3+ by changing:

For $i=3 To $CmdLine[0]
Edited by Ejoc

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks Guys,

What's cool about scripting is that there are some many different ways to do something. The program uses variable command line options (except for the last one).

wrapper /1=""ProgramName"" /2=""path\Exe"" /3=""commandline"" /4=CAPM"

Not the best hunk of code that I ever wrote but it seems to work. Thanks for sparking my brain and the examples.

;Checks if the /3 is there if not set it to "" if you use $CmdLine[0] in runwait and is empty causes errors

If NOT StringInStr ($CmdlineRaw, "/3") Then
    $CommandLine = ""
ElseIf StringInStr ($CmdlineRaw, "/3") Then
    $CommandLine = StringReplace($CmdLine[3],"/3=", "")
EndIf

;Check for required commandlines /1 and /2
If NOT StringInStr ($CmdlineRaw, "/1=") Then
  MsgBox(4096,"Error", "Commandline Incorrect - wrapper  /1=""ProgramName"" /2=""path\Exe"" /3=""commandline"" /4=CAPM",10)
  Exit (100)
EndIf
............
Edited by davezub

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