Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted

Hello you can create your own  arguments recognition  rutine.

 

Saludos

Posted
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?

Posted

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

Posted

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...

Posted

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

Posted

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.

  • 1 month later...
Posted

Hello folks,

Today I am also fighting with parametering. With the compiled file I want to add two parameters: the number of cycles and path for the log file. 

I have the following code:

If $CmdLine[0] = 0 Then
MsgBox(0, 'Command Line Info', 'No arguments passed, so defaults selected')
$cycles = 5
Elseif $CmdLine[0] = 1 Then
$cycles = $CmdLine[1]
$logpath = (".\Logs") ;\System_Start_stop" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & ".log",1)
Elseif $CmdLine[0] = 2 Then
$cycles =  $CmdLine[1]
$logpath = $CmdLine[2]
Elseif $CmdLine[0] > 2 Then
Exit
EndIf

$logFile = FileOpen($logpath & "\System_Start_stop" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & ".log",1)

The parameter $cycles works fine but the $logpath fails and logging is put in the default folder. Who knows what I do wrong? :)

 

Posted

Hello. fmlk you can check  $logpath  in a console or msgbox to check path is correct. then you will able to check where the issue is.

 

Saludos

Posted

You're writing to console  FileOpen returns instead your Path.

 

Saludos

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
  • Recently Browsing   0 members

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