Jump to content

$CmdLine[0] Help


Zane
 Share

Recommended Posts

I'm testing the autoit Command Line Parameters, when I use my executable without parameters is normally executed but when I use different parameters I get this message, please help me

Posted Image

Code:

Select
    
Case $CmdLine[0] = ""
    MsgBox (0, "", "no parameter was used")
    ;do something 
    
Case $CmdLine[1] = "/p1"
    MsgBox (0, "", "parameter 1 was used")
    ;do something 
    
Case $CmdLine[2] = "/p2"    
    MsgBox (0, "", "parameter 2 was used")
    ;do something 
    
Case $CmdLine[3] = "/p3"
    MsgBox (0, "", "parameter 3 was used")
    ;do something 
    
EndSelect
Link to comment
Share on other sites

If $CmdLine[0] > 0 Then
    For $i = 1 To Ubound($CmdLine) -1
        MsgBox(0, "Result", "Parameter " & $i & " = " & $CmdLine[$i])
    Next
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

thank you very much, but im testing with other commands and i get the same message

for example:

Select
    
Case $CmdLine[0] = ""
    Run ("c:\windows\notepad.exe")
       
Case $CmdLine[1] = "/a"
    RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication1", "Startup")
   
Case $CmdLine[2] = "/b"    
    MsgBox (0, "", "msgbx example")
        
Case $CmdLine[3] = "/c"
    InetGet("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe", "C:\autoit.exe")
    
EndSelect
Edited by Zane
Link to comment
Share on other sites

thank you very much, but im testing with other commands and i get the same message

for example:

Select
    
Case $CmdLine[0] = ""
    Run ("c:\windows\notepad.exe")
       
Case $CmdLine[1] = "/a"
    RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication1", "Startup")
   
Case $CmdLine[2] = "/b"    
    MsgBox (0, "", "msgbx example")
        
Case $CmdLine[3] = "/c"
    InetGet("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe", "C:\autoit.exe")
    
EndSelect

To Empasize what we have been trying to show you. $CmdLine[0] will NEVER be "". It holds the number of elements in the array $CmdLine

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

To Empasize what we have been trying to show you. $CmdLine[0] will NEVER be "". It holds the number of elements in the array $CmdLine

Well I don't quite agree with that :)

if $CmdLine[0] = '' then ConsoleWrite("yes it can" & @CRLF)

@Zane. Your approach could work if you did this

Select

    Case $CmdLine[0] = ""
    Run[/url] ("c:\windows\notepad.exe")

    Case $CmdLine[0] > 0 And $CmdLine[1] = "/a"
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication1", "Startup")

    Case $CmdLine[0] > 1 And $CmdLine[2] = "/b"
    MsgBox(0, "", "msgbx example")

    Case $CmdLine[0] > 2 And $CmdLine[3] = "/c"
    InetGet("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe", "C:\autoit.exe")

EndSelect

But you have to remember that if one parameter matches the case test then you will never get to act on the folowing parameters, so I wouldn't recommend that way of dealing with parameters.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Well I don't quite agree with that :)

if $CmdLine[0] = '' then ConsoleWrite("yes it can" & @CRLF)
True, the point I really should have made is that $CmdLine[0] will never hold a parameter. I'm ot sure that the OP knows what $CmdLine is for either or even knows that the script has to be compiled for it to work properly.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...