Sign in to follow this  
Followers 0
mbkowns

CMD Line Parameter - I read helpfile..

15 posts in this topic

#1 ·  Posted (edited)

If $Cmdline[0] Then
    For $i = 1 To $Cmdline[0]
        Select
            Case $Cmdline[$i] = '-?'
                MsgBox(0x40000, StringTrimRight(@ScriptName, 4) & ' Help', _
                        'Switches are:' & @LF _
                         & @LF & '-a' _
                         & @LF & @TAB & '' _
                         & @LF & '-b' _
                         & @LF & @TAB & '' _
                         & @LF & '-c' _
                         & @LF & @TAB & '' _
                         & @LF & '-d' _
                         & @LF & @TAB & '' _
                         & @LF & '-e' _
                         & @LF & @TAB & '')
                Exit
            Case $Cmdline[$i] = '-a'
                If $CmdLine[0] > 1 Then
    For $i = 2 to $CmdLine[0]
                If StringInStr('-i |', $CmdLine[$i - 1]) Then
                $pa = $CmdLine[$i]
                EndIf
                Next
    EndIf
    IniWrite("c:\a.ini", "File", "Exit", "" & $pa)
            Case $Cmdline[$i] = '-b'
                If $CmdLine[0] > 1 Then
    For $i = 2 to $CmdLine[0]
                If StringInStr('-i |', $CmdLine[$i - 1]) Then
                $pb = $CmdLine[$i]
                EndIf
                Next
    EndIf
    IniWrite("c:\a.ini", "File", "Exit", "" & $pb)
            Case $Cmdline[$i] = '-c'
            Case $Cmdline[$i] = '-d'
            Case $Cmdline[$i] = '-e'
            Case Else
                MsgBox(0x40000, 'Incorrect switch used', 'Command used:' & @LF & $CmdlineRaw _
                         & @LF & @LF & 'Use /? for the switches available.')
                Exit
        EndSelect
    Next
EndIf

My problem is when I run "prog.exe -a 5000 -b 2999" -a will work but -b won't do anything. If I put -b first -a won't do anything. I am trying to achieve the below fuctions.

prog.exe -a 5000 -b 2999 -c 08 -d //test -e

It seems that it just only does the first parameter.

Let me know

thanks

Edited by mbkowns

Share this post


Link to post
Share on other sites



looks like you need to exit a loop after writing it.. ( not sure)

but...........

; you have

If StringInStr('-i |', $CmdLine[$i - 1]) Then

; i think it's

If StringInStr( $CmdLine[$i - 1], '-i |') Then

; example

$cmand = "this line of text"

If StringInStr($cmand, "line") Then MsgBox(0,"test", '"line" was in the string ', 5)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I would break it down into a simpler form myself:

If $Cmdline[0] Then
    $aCMDs = StringSplit('-a,-b,-c,-d,-e,-?', ',')
    For $iCC = 1 To $Cmdline[0]
        For $xCC 1 To UBound($aCMDs) - 1
            If $aCMDs[$xCC] = StringLeft($Cmdline[$iCC], 2) Then
                Switch $xCC
                    Case 1;-a
                        _CMD_a($Cmdline[$iCC])
                    Case 2;-b
                        ;Function 2
                    Case 3;-c
                        ;Function 3
                    Case 4;-d
                        ;Function 4
                    Case 5;-e
                        ;Function 5
                    Case 6;-?
                        _CMD_Help()
                EndSwitch
            EndIf
        Next
    Next
Else
    Exit
EndIf

Func _CMD_Help()
    Return MsgBox(0x40000, StringTrimRight(@ScriptName, 4) & ' Help', _
            'Switches are:' & @LF _
             & @LF & '-a' _
             & @LF & @TAB & '' _
             & @LF & '-b' _
             & @LF & @TAB & '' _
             & @LF & '-c' _
             & @LF & @TAB & '' _
             & @LF & '-d' _
             & @LF & @TAB & '' _
             & @LF & '-e' _
             & @LF & @TAB & '')
EndFunc
Using functions to carry out each individual action so I wasn't lost in what I was doing.

Keep in mind that every space creates a new parameter

Edit:

Added comments to the Cases so you could see what I was linking to in the array easier.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

If $Cmdline[0] Then
    $aCMDs = StringSplit('-a,-b,-c,-d,-e,-?', ',')
    For $iCC = 1 To $Cmdline[0]
      ERROR >  For $xCC 1 To UBound($aCMDs) - 1
            If $aCMDs[$xCC] = StringLeft($Cmdline[$iCC], 2) Then
                Switch $xCC
                    Case 1;-a
        ERROR >                _CMD_a($Cmdline[$iCC])
                    Case 2;-b
                        ;Function 2
                    Case 3;-c
                        ;Function 3
                    Case 4;-d
                        ;Function 4
                    Case 5;-e
                        ;Function 5
                    Case 6;-?
                        _CMD_Help()
                EndSwitch
            EndIf
        Next
    Next
Else
    Exit
EndIf

Func _CMD_Help()
    Return MsgBox(0x40000, StringTrimRight(@ScriptName, 4) & ' Help', _
            'Switches are:' & @LF _
             & @LF & '-a' _
             & @LF & @TAB & '' _
             & @LF & '-b' _
             & @LF & @TAB & '' _
             & @LF & '-c' _
             & @LF & @TAB & '' _
             & @LF & '-d' _
             & @LF & @TAB & '' _
             & @LF & '-e' _
             & @LF & @TAB & '')
EndFunc

I get problems where I put a ERROR >

What needs to go there to fix that I tired a couple things and it didn't help

thanks

KYLE

Share this post


Link to post
Share on other sites
If $Cmdline[0] Then
    $aCMDs = StringSplit('-a,-b,-c,-d,-e,-?', ',')
    For $iCC = 1 To $Cmdline[0]
      ERROR >  For $xCC 1 To UBound($aCMDs) - 1
            If $aCMDs[$xCC] = StringLeft($Cmdline[$iCC], 2) Then
                Switch $xCC
                    Case 1;-a
        ERROR >                _CMD_a($Cmdline[$iCC])
                    Case 2;-b
                        ;Function 2
                    Case 3;-c
                        ;Function 3
                    Case 4;-d
                        ;Function 4
                    Case 5;-e
                        ;Function 5
                    Case 6;-?
                        _CMD_Help()
                EndSwitch
            EndIf
        Next
    Next
Else
    Exit
EndIf

Func _CMD_Help()
    Return MsgBox(0x40000, StringTrimRight(@ScriptName, 4) & ' Help', _
            'Switches are:' & @LF _
             & @LF & '-a' _
             & @LF & @TAB & '' _
             & @LF & '-b' _
             & @LF & @TAB & '' _
             & @LF & '-c' _
             & @LF & @TAB & '' _
             & @LF & '-d' _
             & @LF & @TAB & '' _
             & @LF & '-e' _
             & @LF & @TAB & '')
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

The _CMD_a($var) is a function call. That doesn't exist until you write it, I was only supplying the above as a visual example, not a working one.

I typed the above without error checking... the first error is missing an "=" sign :whistle:

This will not throw an error, but shouldn't work either until you make it work:

If $Cmdline[0] Then
    $aCMDs = StringSplit('-a,-b,-c,-d,-e,-?', ',')
    For $iCC = 1 To $Cmdline[0]
        For $xCC = 1 To UBound($aCMDs) - 1
            If $aCMDs[$xCC] = StringLeft($Cmdline[$iCC], 2) Then
                Switch $xCC
                    Case 1
                        _CMD_a($Cmdline[$iCC])
                    Case 2
                        ;Function 2
                    Case 3
                        ;Function 3
                    Case 4
                        ;Function 4
                    Case 5
                        ;Function 5
                    Case 6
                        _CMD_Help()
                EndSwitch
            EndIf
        Next
    Next
Else
    Exit
EndIf

Func _CMD_Help()
    Return MsgBox(0x40000, StringTrimRight(@ScriptName, 4) & ' Help', _
            'Switches are:' & @LF _
             & @LF & '-a' _
             & @LF & @TAB & '' _
             & @LF & '-b' _
             & @LF & @TAB & '' _
             & @LF & '-c' _
             & @LF & @TAB & '' _
             & @LF & '-d' _
             & @LF & @TAB & '' _
             & @LF & '-e' _
             & @LF & @TAB & '')
EndFunc

Func _CMD_a($sCMD)
    ;Whatever you want this to do if it's -a
EndFunc

sweet I realized the function call part but thought i would point it out anyway let me try it...

thanks

Share this post


Link to post
Share on other sites

Alright that part works but I am having problems doing something with the stuff after the parameter.

prog.exe -a 2020 -b 2929

After each parameter I want to take the numbers or whatever text and make it a variable I can use in autoit. I had it working in the first post of code but it doesnt seem to work in this final snippet.

Thanks again for your help

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Alright that part works but I am having problems doing something with the stuff after the parameter.

prog.exe -a 2020 -b 2929

After each parameter I want to take the numbers or whatever text and make it a variable I can use in autoit. I had it working in the first post of code but it doesnt seem to work in this final snippet.

Thanks again for your help

I knew you were going to run into this issue, if you look further up, I explained if there were spaces it would be considered a new parameter.

2 ways around this... wrap the -a 2020 in quotes eg... "-a 2020" that way it's treated as one string, or do what I do... give it a delimiter to separate it, if my "value" answer isn't going to have spaces.

This is a working model of what I am referring to.

Dim $aMyCmdLine[3] = [2, '-a|2020', '-b|2929']
If $aMyCmdLine[0] Then
    $aCMD = StringSplit('-a,-b', ',')
    For $iCC = 1 To $aMyCmdLine[0]
        For $xCC = 1 To $aCMD[0]
            If StringLeft($aMyCmdLine[$iCC], 2) = $aCMD[$xCC] Then
                Switch $xCC
                    Case 1
                        _CMD_a(_SplitCMD($aMyCmdLine[$iCC]))
                    Case 2
                        _CMD_b(_SplitCMD($aMyCmdLine[$iCC]))
                EndSwitch
            EndIf
        Next
    Next
EndIf


Func _CMD_a($sString)
    ;This is just an example
    Return MsgBox(64, 'Function _CMD_a', 'The string passed to this function was: ' & $sString)
EndFunc

Func _CMD_b($sString)
    ;This is just an example
    Return MsgBox(64, 'Function _CMD_b', 'The string passed to this function was: ' & $sString)
EndFunc

Func _SplitCMD($sString)
    If StringInStr($sString, '|') = 0 Then Return $sString
    Local $aSplit = StringSplit($sString, '|')
    Return $aSplit[2]
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

That works for the numbers that I specify in autoit but If I type something different in it still shows thows numbers.

prog -a 2223939393939 -b 123123123

msgbox's 2220 2229

I guess I am just not fully understanding how to get out that part of it if I type in new numbers or text after the parameters. I used a delimiter of | originally in the first post code but it then wouldn't let me use multiple parameters. Seems like I am the otherway around now I can use multiple parameters and not numbers after.

please help thanks

Share this post


Link to post
Share on other sites

That works for the numbers that I specify in autoit but If I type something different in it still shows thows numbers.

prog -a 2223939393939 -b 123123123

msgbox's 2220 2229

I guess I am just not fully understanding how to get out that part of it if I type in new numbers or text after the parameters. I used a delimiter of | originally in the first post code but it then wouldn't let me use multiple parameters. Seems like I am the otherway around now I can use multiple parameters and not numbers after.

please help thanks

1. The function I provided you was only and example....

You're missing the point...

Run("program.exe -a|2223939393939 -b|123123123")oÝ÷ Ø!£¨»
.Ü+×­é­ë®*miº/z+Ëb¶*.°â·«z)Ú§-¹©lr¸©¶+p¢é]$)jëh×6If $CmdLine[0] Then
    $aCMD = StringSplit('-a,-b', ',')
    For $iCC = 1 To $CmdLine[0]
        For $xCC = 1 To $aCMD[0]
            If StringLeft($CmdLine[$iCC], 2) = $aCMD[$xCC] Then
                Switch $xCC
                    Case 1
                        _CMD_a(_SplitCMD($CmdLine[$iCC]))
                    Case 2
                        _CMD_b(_SplitCMD($CmdLine[$iCC]))
                EndSwitch
            EndIf
        Next
    Next
EndIf


Func _CMD_a($sString)
    ;This is just an example
    Return MsgBox(64, 'Function _CMD_a', 'The string passed to this function was: ' & $sString)
EndFunc

Func _CMD_b($sString)
    ;This is just an example
    Return MsgBox(64, 'Function _CMD_b', 'The string passed to this function was: ' & $sString)
EndFunc

Func _SplitCMD($sString)
    If StringInStr($sString, '|') = 0 Then Return $sString
    Local $aSplit = StringSplit($sString, '|')
    Return $aSplit[2]
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

That code works and tells me which parameter I give it. What is the variable that gives the number after the parameter because it doesn't give that.

prog -a 2235 -b 234234

thanks

Share this post


Link to post
Share on other sites

That code works and tells me which parameter I give it. What is the variable that gives the number after the parameter because it doesn't give that.

prog -a 2235 -b 234234

thanks

I want to be able to go to command line and type in

prog -a 23sdfjsdfjh -b 12381283

The numbers need to be able to change depending on what I need to put in. In my autoit script it needs to see those strings as varibles that I can then use in my code.

Let me know if your following me here

Share this post


Link to post
Share on other sites

I want to be able to go to command line and type in

prog -a 23sdfjsdfjh -b 12381283

The numbers need to be able to change depending on what I need to put in. In my autoit script it needs to see those strings as varibles that I can then use in my code.

Let me know if your following me here

1. For every space you must know that is going to be a parameter within $CmdLine[n]

2. If you want -a to contain 23sdfjsdfjh then you must either skip every 2 parameters and say ok, the next parameter after -a is going to be the information I need, and code the $CmdLine option I provided according to that.

3. The smarter way IMO, because there may come a time where you are not passing a 2nd parameter to the autoit file for that specific switch would be to separate them like -a|23sdfjsdfjh -b|12381283, this way, you can script your $CmdLine option in the receiving script that if it finds a | in the $CmdLine[n] that it needs to split that into an array, and go to the proper function and the 2nd part of the array is the information you need to log.

If you are still having issues, then show how you have tried to mod the $CmdLine option I've provided, and exactly how you are sending the information... I'm not much on playing the guessing game, as it wastes your time and more importantly ours.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I finnally got everything to work exactly like I wanted!!!!!!!!! :whistle:

Thanks Smoke for all your help here is my final code.

It will take

Install.exe -i 1 -s 202 -t 08 -n //testserver01 -u -?

I can do one parameter two any order and it will take the string after and put it in an ini file everytime.

If $CmdLine[0] Then
    $aCMD = StringSplit('-?,-i,-s,-t,-n,-u', ',')
    For $iCC = 1 To $CmdLine[0]
        For $xCC = 1 To $aCMD[0]
            If StringLeft($CmdLine[$iCC], 6) = $aCMD[$xCC] Then
                Switch $xCC
                    Case 1
                        _CMD_Q(_SplitCMD($CmdLine[$iCC]))
                    Case 2
                        _CMD_i(_SplitCMD($CmdLine[$iCC]))
                    Case 3
                        _CMD_s(_SplitCMD($CmdLine[$iCC]))
                    Case 4
                        _CMD_t(_SplitCMD($CmdLine[$iCC]))
                    Case 5
                        _CMD_n(_SplitCMD($CmdLine[$iCC]))
                    Case 6
                        _CMD_u(_SplitCMD($CmdLine[$iCC]))
                EndSwitch
            EndIf
        Next
    Next
EndIf


Func _CMD_i($sString)
    global $i
    If $Cmdline[$iCC] = '-i' Then
        
        If $CmdLine[0] > 1 Then
        For $iCC = 2 to $CmdLine[0]
        If StringInStr('-i |', $CmdLine[$iCC - 1]) Then
        $i = $CmdLine[$iCC]
        EndIf
        Next
        EndIf

            IniWrite("c:\a.ini", "cmd", "i", "" & $i)
        
        endif
    Return MsgBox(64, 'Function _CMD_i', 'The string passed to this function was: ' & $CmdLine[0])
EndFunc

Func _CMD_s($sString)
        global $s
    If $Cmdline[$iCC] = '-s' Then
        
        If $CmdLine[0] > 1 Then
        For $iCC = 2 to $CmdLine[0]
        If StringInStr('-s |', $CmdLine[$iCC - 1]) Then
        $s = $CmdLine[$iCC]
        EndIf
        Next
        EndIf

            IniWrite("c:\a.ini", "cmd", "s", "" & $s)
        
        endif
    Return MsgBox(64, 'Function _CMD_s', 'The string passed to this function was: ' & $CmdLine[0])
EndFunc

Func _CMD_t($sString)
    global $t
    If $Cmdline[$iCC] = '-t' Then
        
        If $CmdLine[0] > 1 Then
        For $iCC = 2 to $CmdLine[0]
        If StringInStr('-t |', $CmdLine[$iCC - 1]) Then
        $t = $CmdLine[$iCC]
        EndIf
        Next
        EndIf

            IniWrite("c:\a.ini", "cmd", "t", "" & $t)
        
        endif
    Return MsgBox(64, 'Function _CMD_t', 'The string passed to this function was: ' & $CmdLine[0])

EndFunc

Func _CMD_n($sString)
    global $n
    If $Cmdline[$iCC] = '-n' Then
        
        If $CmdLine[0] > 1 Then
        For $iCC = 2 to $CmdLine[0]
        If StringInStr('-n |', $CmdLine[$iCC - 1]) Then
        $n = $CmdLine[$iCC]
        EndIf
        Next
        EndIf

            IniWrite("c:\a.ini", "cmd", "n", "" & $n)
        
        endif
    Return MsgBox(64, 'Function _CMD_n', 'The string passed to this function was: ' & $CmdLine[0])

EndFunc

Func _CMD_u($sString)
    global $u
    If $Cmdline[$iCC] = '-u' Then
        
        If $CmdLine[0] > 1 Then
        For $iCC = 2 to $CmdLine[0]
        If StringInStr('-u |', $CmdLine[$iCC - 1]) Then
        $u = $CmdLine[$iCC]
        EndIf
        Next
        EndIf

            IniWrite("c:\a.ini", "cmd", "u", "" & $u)
        
        endif
    Return MsgBox(64, 'Function _CMD_u', 'The string passed to this function was: ' & $CmdLine[0])

EndFunc

Func _CMD_Q($sString)
              MsgBox(0x40000, StringTrimRight(@ScriptName, 4) & ' Switches', _
                        'Install.exe -i 1 -s 202 -t 08 -n //testserver01 -u -?' & @LF _
                         & @LF & '-i' _
                         & @LF & @TAB & 'NOTES HERE' _
                         & @LF & '-s' _
                         & @LF & @TAB & 'NOTES HERE' _
                         & @LF & '-t' _
                         & @LF & @TAB & 'NOTES HERE' _
                         & @LF & '-n' _
                         & @LF & @TAB & 'NOTES HERE' _
                         & @LF & '-u' _
                         & @LF & @TAB & 'NOTES HERE' _
                         & @LF & '-?' _
                         & @LF & @TAB & 'HELP')
                      
        
    
EndFunc

Func _SplitCMD($sString)
    If StringInStr($sString, '|') = 0 Then Return $sString
    Local $aSplit = StringSplit($sString, '|')
    Return $aSplit[2]
EndFunc

Share this post


Link to post
Share on other sites

:whistle:

Well, if it works great!!... Not really what I had in mind :) (It's doing a lot of repeat stuff), but now you at least have a mold.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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