MattHiggs

Command line arguments passed to compiled script

9 posts in this topic

Hello all,

I am trying to, for the first time, create a command line tool in autoit to be utilized in conjunction with an application I am writing.  I have been looking at the help file, and, from what I see, the arguments passed to the compiled executable have to be in a particular order in order for autoit to know which commands are which.  I was wondering if there was a way to write a command line tool in autoit that recognizes arguments more like a normal windows command line tool, for example:

mytool.exe /uniqueidentifier argument

Please let me know when you can.

Share this post


Link to post
Share on other sites



Hello,

Per my understanding, we cannot get the arguments directly using the command line switches as mentioned in the question.

But as detailed in the help file, we can get the commandline arguments in an array. If need to put switches in argument, we can parse this array and check for these switches.

 

Thanks

Anoop

Share this post


Link to post
Share on other sites

Hello you can create your own  arguments recognition  rutine.

 

Saludos

Share this post


Link to post
Share on other sites
2 minutes ago, Danyfirex said:

Hello you can create your own  arguments recognition  rutine.

 

Saludos

By this suggestion, would an example of what you are referring to be to split the argument string with a specified delimiter, and determine what function to run based on results of first string?

Share this post


Link to post
Share on other sites

I think you can do something like this.

 

If $CmdLine[0] Then
    If StringInStr($CmdLine[1], "/") = 1 And $CmdLine[0] >= 2 Then ;I check if the first parameter is a command and if it has the correct parameters
        Local $sMyFunction = StringReplace($CmdLine[1], "/", "_") ;Convert to correct function name
        Local $sMyArgument = $CmdLine[2] ;get my parameter
        Call($sMyFunction,$sMyArgument) ;Call the function
    EndIf
Else
;show -help file
EndIf



Func _uniqueidentifier($sArgument)
    MsgBox(0, "", "Im /uniqueidentifier and my argument is: " & $sArgument & @CRLF)
EndFunc   ;==>_uniqueidentifier

call from cmd like:

myScript.exe /uniqueidentifier "Hola soy Danyfirex"

 

Saludos

1 person likes this

Share this post


Link to post
Share on other sites

Insightful.  Thanks friend.  +1 for you.

Share this post


Link to post
Share on other sites

Another quick question concerning this.  Like I said, this script would a piece of a complete solution that I am developing right now.  Meaning I will also be calling the script from the main application file with the necessary parameters.  My question is this: how, if possible, can I "return" the output that the script generates to a variable in the original application file that ran it?  Would I use ConsoleWrite() to do this?  Is it impossible?  I don't know...

Share this post


Link to post
Share on other sites

There are many ways to do that.

I usually use this methods.

WM_COPYDATA

Write to a file.

Send data to a control in main process.

 

Saludos

Share this post


Link to post
Share on other sites

Yeah, thats what I ended up doing anyway.  What I was trying to accomplish was to have the script essentially "return" the value I need directly to the main executable without creating, writing to, or reading from any files.  Pretty much like how a function returns a variable when called.

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