Jump to content
Sign in to follow this  
Zane

$CmdLine[0] Help

Recommended Posts

Zane

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

Share this post


Link to post
Share on other sites
Mat

For $i = 1 to $CmdLine[0]
   If $CmdLine[$i] = "/p" & $i Then MsgBox (0, "", "parameter " & $i & " was used")
Next

haven't tested, written on the fly, but its the idea that counts :)

Mat

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Zane

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

Share this post


Link to post
Share on other sites
dantay9

You need to read $CMDLine[0] to find out how many elements are in the array. You can't check $CMDLine[3] if there were only two parameters given.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
martin

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.

Share this post


Link to post
Share on other sites
GEOSoft

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!"

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.