FredMellink Posted August 26, 2013 Share Posted August 26, 2013 Hello, I created an AutoIT duration test for an application and want to run the compiled exe of the test in a test suite, via the command line: MyDurationTest.exe c:My_LogPathNameOfLogFile.txt How can I prepare the script that it uses the log path and name of the log file. I am pretty much beginner on AutoIT and not real programmer, but it's fun to do some scripting.Thanks for feedback. Regards, Fred Link to comment Share on other sites More sharing options...
FireFox Posted August 26, 2013 Share Posted August 26, 2013 (edited) Hi,Take a look at the helpfile at the "Running Scripts" index, you will have the "Command Line Parameters" section.Edit: Btw, Welcome to the autoit forum Br, FireFox. Edited August 26, 2013 by FireFox Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2013 Share Posted August 26, 2013 See "Running Scripts" section of the help file. It's quits comprehensive. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 Thanks for your superfast reply! In the mean time I found it, but I miss some "example code. How do I use $CmdLine in my script? For me as beginner and non-programmer it is not so comprehensive Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2013 Share Posted August 26, 2013 Compile and run with path If $CmdLine[0] = 0 Then Exit MsgBox(0, 'Command Line Info', 'No arguments passed') EndIf MsgBox(0, 'Command Line Info', 'There are ' & $CmdLine[0] & ' arguments passed') MsgBox(0, 'Command Line Info', 'The first argument is ' & $CmdLine[1]) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 Thanks John, I think I can use this info and make it work. When on command line is typed "MyTest.exe c:mylogsmylogfile.txt" then I suppose that in my script can use it with code like: $logfile=$CmdLine[1] FileWrite($logFile, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & " no errors" & @CR) Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2013 Share Posted August 26, 2013 That's correct. You can many parameters, just separate them with a space as you did the first. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 I have a simple Notepadtest for this kind of testing. My first attempt fails and code of the notepad test is below as example expandcollapse popup#include <WindowsConstants.au3> #include <Date.au3> Global $answer, $timer, $Secs, $Mins, $Hour, $Time1, $Time2, $CmdLine If $CmdLine[0] = 0 Then Exit MsgBox(0, 'Command Line Info', 'No arguments passed') EndIf MsgBox(0, 'Command Line Info', 'There are ' & $CmdLine[0] & ' arguments passed') MsgBox(0, 'Command Line Info', 'The first argument is ' & $CmdLine[1]) ;DirCreate("C:\DurationLog\NotepadTest") ; Start and Wait for the for Notepad Run( "Notepad.exe", @WindowsDir) If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("This is for learning only{ENTER}{ENTER}") $answer = MsgBox(4, "output", "Notepad is active!... Let's begin! This script tells with randomly selected lines about AutoIT. After 20 lines it stops automatically. Do you want to continue?") If $answer = 7 Then ; no is clicked WinClose("Untitled - Notepad") Send("!n") Exit EndIf WinWaitActive("Untitled - Notepad") ;$Time1=_Date_Time_GetLocalTime() $logFile = FileOpen($CmdLine[1]) ;$logFile = FileOpen("C:\DurationLog\NotepadTest\NotepadTest_.csv",1) FileWrite($logFile, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "|") ;FileWrite("fmlk_notepadtest.csv", "Start notepad script: ," & _Date_Time_SystemTimeToDateTimeStr($Time1) & @CRLF) $i = 0 While $i <10 $delay = Random(50,5000,1) $choice = Random(1,7,1) Switch $choice Case 1 AutoIT1() $i = $i + 1 Case 2 AutoIT2() $i = $i + 1 Case 3 AutoIT3() $i = $i + 1 Case 4 AutoIT4() $i = $i + 1 Case 5 AutoIT5() $i = $i + 1 Case 6 AutoIT6() $i = $i + 1 Case 7 AutoIT7() $i = $i + 1 EndSwitch Sleep($delay) WEnd FileWrite($logFile, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "|" & $i & "|" & "0" & "|" & "0" & "|" & " no errors" & @CR) ; $Time2=_Date_Time_GetLocalTime() ; FileWrite("fmlk_notepadtest.csv", "Finish notepad script: " & _Date_Time_SystemTimeToDateTimeStr($Time2) & @CRLF) ; FileWrite("C:\DurationLog\NotepadTest\fmlk_notepadtest.csv", _Date_Time_SystemTimeToDateTimeStr($Time1) & "," & _Date_Time_SystemTimeToDateTimeStr($Time2) & "," & $i & "cycles" & @CRLF) ; FileWrite("fmlk_notepadtest.csv", "after " & $i & " cycles") ; FileWrite("C:\DurationLog\NotepadTest\fmlk_notepadtest.csv", @CR) AutoIT8() ;WinClose("Untitled - Notepad") ; Send("!n") ; Exit Func AutoIT1() ; None $number= Random(1,10,1) If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("AutoIT is a powerful scripting tool and can also give random numbers:" & $number & "{ENTER}") ;FileWrite("debuglogging.csv", "counter = ," & "AutoIT1 selected " & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT1 selected , " & @CR) EndFunc Func AutoIT2() ; Natural If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("AutoIT is easy to use and has relatively small learning curve{ENTER}") ;FileWrite("debuglogging.csv", ",AutoIT2 selected " & "counter = ," & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT2 selected , " & @CR) EndFunc Func AutoIT3() ; Natural If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("AutoIT scripts can easily be converted to standalone applications{ENTER}") ;FileWrite("debuglogging.csv", ",AutoIT3 selected " & "counter = ," & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT3 selected , " & @CR) EndFunc Func AutoIT4() ; Natural If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("AutoIT is freeware and may be freely installed on any PC or system{ENTER}") ;FileWrite("debuglogging.csv", ",AutoIT4 selected " & "counter = ," & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT4 selected , " & @CR) EndFunc Func AutoIT5() ; Natural If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("AutoIT seems to be very useful to build duration tests for NanoExerciser{ENTER}") ;FileWrite("debuglogging.csv", ",AutoIT5 selected " & "counter = ," & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT5 selected , " & @CR) EndFunc Func AutoIT6() ; Natural If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("AutoIT has a 'Window Info' tool for controlling GUI applications{ENTER}") ;FileWrite("debuglogging.csv", ",AutoIT6 selected " & "counter = ," & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT6 selected , " & @CR) EndFunc Func AutoIT7() ; Natural If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") Send("More information can be found on the web: http://www.autoitscript.com/site/autoit/{ENTER}") $Delay = (2000) ;FileWrite("debuglogging.csv", ",AutoIT7 selected" & "counter = ," & $i & @CR) FileWrite("C:\DurationLog\NotepadTest\debuglogging.csv", @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & " counter = " & $i & ", AutoIT7 selected , " & @CR) EndFunc Func AutoIT8() ;Finish If Not WinActive("Untitled - Notepad") Then _ WinWaitActive("Untitled - Notepad") $answer = MsgBox(0, "Thanks for your attention", "More information can be found on the web: http://www.autoitscript.com/site/autoit/") If $answer = 1 Then ; OK is clicked WinClose("Untitled - Notepad") Send("!n") Exit EndIf EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2013 Share Posted August 26, 2013 "Fails" is not enough information/ AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 Unfortunately I was not able to upload a screenshot. But the AutoIT Error dialog tells: Line 9 (File "C:SnapsAutoITfrednotepad_exercise20130826.au3"): EndIf MsgBox(0, 'Command Line Info', There are ' & $CmdLine[0] & 'arguments passed') EndIf ^ ERROR Error: Illegal text at the end of statement (one statement per line). ----------------------------- Thanks for helping me!! Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 Got it working. There was error in your code. I must be: If $CmdLine[0] = 0 Then Exit MsgBox(0, 'Command Line Info', 'No arguments passed') Else MsgBox(0, 'Command Line Info', 'There are ' & $CmdLine[0] & ' arguments passed') MsgBox(0, 'Command Line Info', 'The first argument is ' & $CmdLine[1]) EndIf Link to comment Share on other sites More sharing options...
FireFox Posted August 26, 2013 Share Posted August 26, 2013 As a beginner, you should use the SciTE editor and run au3check.It will show you the syntax errors.Think a little and find out why EndIf MsgBox... is incorrect.Br, FireFox. Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 However I added "C:fredtesttestlog.txt" as parameter but the logfile is not writen. So still things to dig into. Link to comment Share on other sites More sharing options...
TheSaint Posted August 26, 2013 Share Posted August 26, 2013 (edited) You might also want to check out the UDF (User Defined Functions) section of the Help file, as it has a _FileWriteLog function, that includes time and date, plus any text you provide. That frees you from the need of using FileOpen and FileClose. Edited August 26, 2013 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2013 Share Posted August 26, 2013 Pretty sure you need a backslash. c: AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
FredMellink Posted August 26, 2013 Author Share Posted August 26, 2013 Final question for finalizing this issue: When I use "pathlogfile" as one parameter how can I create the path and logfile to append logdata too. I also tried two paramters: "path" and "logfile" E.g. $logFile = FileOpen(($CmdLine[1] & $CmdLine[2]),1) doesn't work. Thanks for your help. Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2013 Share Posted August 26, 2013 Show all relevant exact code in tags. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
FredMellink Posted August 27, 2013 Author Share Posted August 27, 2013 I tried: If $CmdLine[0] = 0 Then Exit MsgBox(0, 'Command Line Info', 'No arguments passed') Else MsgBox(0, 'Command Line Info', 'There are ' & $CmdLine[0] & ' arguments passed') MsgBox(0, 'Command Line Info', 'The first argument is ' & $CmdLine[1]) MsgBox(0, 'Command Line Info', 'The second argument is ' & $CmdLine[2]) DirCreate($CmdLine[1]) $logFile = _FileCreate($CmdLine[1] & $CmdLine[2]) MsgBox(0, "Check logfile creation", 'The logfile is: ' & $logFile) _FileWriteLog($logFile, "version20130826") EndIf to test the paramertrizing but the output is $logfile = 1 Link to comment Share on other sites More sharing options...
FredMellink Posted August 27, 2013 Author Share Posted August 27, 2013 But the main problem is that _FileCreate() needs $filepath as input, but DirCreate the path only. Nice puzzle for beginners like me. Link to comment Share on other sites More sharing options...
JohnOne Posted August 27, 2013 Share Posted August 27, 2013 What is string you are passing to exe? eg: c:myexe.exe c:pathtofolder file.ext" AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
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