Jump to content
Sign in to follow this  
FredMellink

Running compiled exe on command line with log path as parameter

Recommended Posts

FredMellink

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

 

 

Share this post


Link to post
Share on other sites
FireFox

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 by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FredMellink

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 :)

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
FredMellink

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)

Share this post


Link to post
Share on other sites
FredMellink

I have a simple Notepadtest for this kind of testing. My first attempt fails and code of the notepad test is below as example

#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

Share this post


Link to post
Share on other sites
FredMellink

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

Share this post


Link to post
Share on other sites
FredMellink

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

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FredMellink

However I added "C:fredtesttestlog.txt" as parameter but the logfile is not writen. So still things to dig into.

Share this post


Link to post
Share on other sites
TheSaint

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 by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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)

userbar.png

Share this post


Link to post
Share on other sites
FredMellink

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.

Share this post


Link to post
Share on other sites
FredMellink

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

Share this post


Link to post
Share on other sites
FredMellink

But the main problem is that _FileCreate() needs $filepath as input, but DirCreate the path only.

Nice puzzle for beginners like me.

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  

×