Sign in to follow this  
Followers 0
nevodj

Command-Line Parameters

7 posts in this topic

Hi

Can someone help me, i can not get command line parameters to work with AutoIT.

If I write a simple script like:

MsgBox(0,"Parameters", $CmdLine[1])

And convert it to an exe, then run it with any parameter e.g. abc123, it opens the C:\Documents folder?

my script is complete apart from this bit, can someone help!

thanks

Share this post


Link to post
Share on other sites



Hi nevodj,

if you use paramaters that have spaces / blanks in it you need to quote them.

e.g. script.exe parameter1 "parameter 2"


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Thanks Hannes,

i created a basic script as above to test this function.

============================

MsgBox(0,"Parameters", $CmdLine[1])

============================

Then compiled it to 'test.exe' on my desktop.

when i run this from the command line using C:\Documents and Settings\User\Desktop\test.exe param1 or C:\Documents and Settings\User\Desktop\test.exe "param1"

it opens the C:\Documents folder?! shouldnt it display a msgbox with "param1" in the lines?

when i run it with no args it comes up "Array variable has incorrect number of subscripts or subscript dimension range exceeded.:"

THe help file on this topic is not very comprehensive.

appreciate your help

Share this post


Link to post
Share on other sites

This should work properly:

Global $parameter
If Not $CmdLine[0] Then
    $parameter = "No parameter(s) was/were entered"
Else
    For $i = 1 To $CmdLine[0]
        $parameter &= $CmdLine[$i] & @LF
    Next
EndIf

MsgBox(0, "Test", "Parameter(s) entered: " & @CRLF  & $parameter)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks UEZ,

If i compile your script to C:\Documents and Settings\User\Desktop\test.exe

and then run it by typing the following in Run - C:\Documents and Settings\User\Desktop\test.exe testparam

It still opens the C:\Documents folder.

What am i doing wrong? If i dont specify any args i get the msgbox saying none specified.

Thanks

Share this post


Link to post
Share on other sites

Try this: "C:\Documents and Settings\User\Desktop\test.exe" testparam

For some reason, your "Run" is considering the white spaces in the file path as parameter delimiters - by enclosing the path in quotes, you will force it to be recognized as a single entity.

You can test it this way: put your script on c:\ then run it - you'll see that it works.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Ah sweet, thanks heaps enaiman!

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