MattHiggs Posted September 17, 2016 Posted September 17, 2016 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.
Anoop Posted September 17, 2016 Posted September 17, 2016 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
Danyfirex Posted September 17, 2016 Posted September 17, 2016 Hello you can create your own arguments recognition rutine. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
MattHiggs Posted September 17, 2016 Author Posted September 17, 2016 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?
Danyfirex Posted September 17, 2016 Posted September 17, 2016 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 MattHiggs 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
MattHiggs Posted September 17, 2016 Author Posted September 17, 2016 Insightful. Thanks friend. +1 for you.
MattHiggs Posted September 17, 2016 Author Posted September 17, 2016 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...
Danyfirex Posted September 17, 2016 Posted September 17, 2016 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 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
MattHiggs Posted September 23, 2016 Author Posted September 23, 2016 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.
fmlk Posted October 26, 2016 Posted October 26, 2016 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?
Danyfirex Posted October 26, 2016 Posted October 26, 2016 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 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
fmlk Posted October 27, 2016 Posted October 27, 2016 Hello Danyfiex, $logpath returns not e.g. "C:\my_test_log" but just 1 Regards, Fred
fmlk Posted October 27, 2016 Posted October 27, 2016 Here is a debug script for review, what goes wrong. parametrizing.au3
Danyfirex Posted October 27, 2016 Posted October 27, 2016 You're writing to console FileOpen returns instead your Path. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now