Jump to content

Create a log.txt file that use for debugging purpose - (Moved)


wan
 Share

Go to solution Solved by Zedna,

Recommended Posts

Hello. I want to ask on how Autoit exe can send a log after every time my program running ? It is for debug purpose to easily know whic line does not execute correctly. For a better, I want Autoit to send the log to me through email.

Below is my scripts. Thank You

 

 

TMGAD0001.au3

Edited by wan
Link to comment
Share on other sites

  • Moderators

Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Zedna The sVMS2000.exe start in multiple window thus error box message appear Abnormalities Runtime. Can you check my script?

 

 

#include <Date.au3>
#include <MsgBoxConstants.au3>
#RequireAdmin

Global $sPath = "\\10.174.10.9\SPOON\TMGAD0001\INPUT\"
Global $tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime(_Date_Time_GetSystemTime())
Global $sFileName1 = "FR_IP_79_" & _WinAPI_GetDateFormat(0, $tLocal, 0, 'yyyyMMdd') & _WinAPI_GetTimeFormat(0, $tLocal, $TIME_FORCE24HOURFORMAT, 'HHmm')
Global $sFileName2 = "FR_IP_82_" & _WinAPI_GetDateFormat(0, $tLocal, 0, 'yyyyMMdd') & _WinAPI_GetTimeFormat(0, $tLocal, $TIME_FORCE24HOURFORMAT, 'HHmm')
Global $sFileName3 = "FR_IP_47_" & _WinAPI_GetDateFormat(0, $tLocal, 0, 'yyyyMMdd') & _WinAPI_GetTimeFormat(0, $tLocal, $TIME_FORCE24HOURFORMAT, 'HHmm')
Global $sFileName4 = "FR_IP_49_" & _WinAPI_GetDateFormat(0, $tLocal, 0, 'yyyyMMdd') & _WinAPI_GetTimeFormat(0, $tLocal, $TIME_FORCE24HOURFORMAT, 'HHmm')
Global $sWindow1 = "[TITLE:" & $sFileName1 & ".xlsx - Excel; CLASS:XLMAIN]"
Global $sWindow2 = "[TITLE:" & $sFileName2 & ".xlsx - Excel; CLASS:XLMAIN]"
Global $sWindow3 = "[TITLE:" & $sFileName3 & ".xlsx - Excel; CLASS:XLMAIN]"
Global $sWindow4 = "[TITLE:" & $sFileName4 & ".xlsx - Excel; CLASS:XLMAIN]"
Sleep (1000)


run("E:\sVMS2000\sVMS2000.exe")


Local $hWnd = WinWait("[TITLE:Login; CLASS:Qt5QWindowIcon]", "")
Sleep(1000)

; Click "Login"
ControlClick( "Login", "", $hWnd ,"left", 1, 277, 490 )

Local $hWnd = WinWait("[TITLE:sVMS2000; CLASS:Qt5QWindowIcon]", "")
$WinPos = WinGetPos($hWnd)
Sleep(1000)

; ***************************************************************
; Perform Face Recognition Device 10.174.120.79 (Terminal A)
; ***************************************************************

; Click "Face Manage"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 667, 195 )
Sleep(1000)

; Click "Default Group"
ControlClick( "sVMS2000", "", $hWnd, "left", 2, 37, 119 )
Sleep(1000)

; Click 10.174.10.79 "Terminal A" Device
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 80, 141 )
Sleep(1000)

; Click "Search"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1455, 145 )
Sleep(10000)

 If WinActive ("MessBox") Then
 ; Close the Excel file.
 WinClose("MessBox")

 ; Activate the sVMS2000 window.
Local $hWnd = WinWait("[TITLE:sVMS2000; CLASS:Qt5QWindowIcon]", "")

; Uncheck "Export Picture"
 ControlClick( "sVMS2000", "", $hWnd, "left", 1, 245, 838 )
 Sleep(1000)

Else

 ; Click "Export"
 ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1530, 145 )
 Sleep(2000)

 ; Wait for Explorer Window
 Local $hWnd1 = WinWait("[TITLE:Save; CLASS:#32770]", "")

 ; Click on the text box
 ControlClick ( $hWnd1, "", 1001 )
 Sleep(10000)

 ; Enter file saved name.
 ControlSetText( $hWnd1, "", 1001, $sPath & $sFileName1 )
 Sleep(10000)

 ; Click SAVE
 ControlClick ( $hWnd1, "", 1 )
 Sleep(10000)

 ; Wait for the Excel File to Appear
WinWait($sWindow1, "")
 Sleep(2000)

 ; Close the Excel file.
 WinClose($sWindow1, "")
 Sleep(500)


EndIf


MyLog('start of section two ...')
Sleep(500)
; ***************************************************************
; Perform Face Recognition Device 10.174.120.82 (Terminal B)
; ***************************************************************

; Activate the sVMS2000 window.
Local $hWnd = WinWait("[TITLE:sVMS2000; CLASS:Qt5QWindowIcon]", "")

; Click 10.174.10.82 "Terminal B" Device
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 80, 162 )
Sleep(1000)

; Click "Search"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1455, 145 )
Sleep(10000)


If WinActive ("MessBox") Then
; Close the error box.
WinClose("MessBox")
Sleep(500)
Else
;WinWaitClose("MessBox") ; Wait until the window is closed
   ;ProcessWaitClose("") ; Wait until the window is closed via Process Close
   ;MsgBox(0, "MessBox", "MessBox  has been closed", 5)
;ElseIf WinExists("MessBox") = "0" Then
;ElseIf ProcessExists("") = "0" Then
   ;MsgBox(0, "MessBox", "That window doesn't exist!", 5)

   ; Click "Export"
   ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1530, 145 )
   Sleep(2000)

   ; Wait for Explorer Window
   Local $hWnd1 = WinWait("[TITLE:Save; CLASS:#32770]", "")

   ; Click on the text box
   ControlClick ( $hWnd1, "", 1001 )
   Sleep(10000)

   ; Enter file saved name.
   ControlSetText( $hWnd1, "", 1001, $sPath & $sFileName2 )
   Sleep(10000)

   ; Click SAVE
   ControlClick ( $hWnd1, "", 1 )
   Sleep(60000)

   ; Wait for the Excel File to Appear.
   WinWait($sWindow2, "")
   Sleep(2000)

   ; Close the Excel file.
   WinClose($sWindow2, "")
   Sleep(500)


EndIf
Sleep(500)

MyLog('start of section 3 ...')
Sleep(500)
; ***************************************************************
; Perform Face Recognition Device 10.174.120.47 (Terminal C)
; ***************************************************************

; Activate the sVMS2000 window.
Local $hWnd = WinWait("[TITLE:sVMS2000; CLASS:Qt5QWindowIcon]", "")

; Click 10.174.10.47 "Terminal C" Device
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 80, 183 )
Sleep(1000)

; Click "Search"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1455, 145 )
Sleep(60000)

If WinActive ("MessBox") Then
; Close the error box
WinClose("MessBox")
Sleep(500)
;WinWaitClose("MessBox") ; Wait until the window is closed
   ;ProcessWaitClose("") ; Wait until the window is closed via Process Close
   ;MsgBox(0, "MessBox", "MessBox has been closed", 5)
;ElseIf WinExists("MessBox") = "0" Then
;ElseIf ProcessExists("") = "0" Then
   ;MsgBox(0, "MessBox", "That window doesn't exist!", 5)

Else

; Click "Export"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1530, 145 )
Sleep(2000)

; Wait for Explorer Window
Local $hWnd1 = WinWait("[TITLE:Save; CLASS:#32770]", "")

; Click on the text box
ControlClick ( $hWnd1, "", 1001 )
Sleep(10000)

; Enter file saved name.
ControlSetText( $hWnd1, "", 1001, $sPath & $sFileName3 )
Sleep(10000)

; Click SAVE
ControlClick ( $hWnd1, "", 1 )
Sleep(60000)

; Wait for the Excel File to Appear.
WinWait($sWindow3, "")
Sleep(2000)

; Close the Excel file.
WinClose($sWindow3, "")
Sleep(500)

_WriteErrorLog("3")
EndIf
Sleep(500)

MyLog('start of section 4 ...')
Sleep(500)
; ***************************************************************
; Perform Face Recognition Device 10.174.120.49 (Terminal D)
; ***************************************************************

; Activate the sVMS2000 window.
Local $hWnd = WinWait("[TITLE:sVMS2000; CLASS:Qt5QWindowIcon]", "")

; Click 10.174.10.49 "Terminal D" Device
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 80, 204 )
Sleep(1000)

; Click "Search"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1455, 145 )
Sleep(60000)

If WinActive ("MessBox") Then
; Close the error box.
WinClose("MessBox")
Sleep(500)
;WinWaitClose("MessBox") ; Wait until the window is closed
   ;ProcessWaitClose("") ; Wait until the window is closed via Process Close
   ;MsgBox(0, "MessBox", "MessBox  has been closed", 5)
;ElseIf WinExists("MessBox") = "0" Then
;ElseIf ProcessExists("") = "0" Then
   ;MsgBox(0, "MessBox", "That window doesn't exist!", 5)

Else

; Click "Export"
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1530, 145 )
Sleep(2000)

; Wait for Explorer Window
Local $hWnd1 = WinWait("[TITLE:Save; CLASS:#32770]", "")

; Click on the text box
ControlClick ( $hWnd1, "", 1001 )
Sleep(10000)

; Enter file saved name.
ControlSetText( $hWnd1, "", 1001, $sPath & $sFileName4 )
Sleep(10000)

; Click SAVE
ControlClick ( $hWnd1, "", 1 )
Sleep(60000)

; Wait for the Excel File to Appear.
WinWait($sWindow4, "")
Sleep(2000)

; Close the Excel file.
WinClose($sWindow4, "")
Sleep(500)


EndIf
Sleep(500)


MyLog('start of section 5 ...')
Sleep(500)
; ***************************************************************
; Close/Exit the sVMS2000 Application.
; ***************************************************************

; Activate the sVMS2000 window.
Local $hWnd = WinWait("[TITLE:sVMS2000; CLASS:Qt5QWindowIcon]", "")

; Click EXIT.
ControlClick( "sVMS2000", "", $hWnd, "left", 1, 1580, 20 )

; Wait for the Exit Confirmation window.
Local $hWnd1 = WinWait("[TITLE:MessBox; CLASS:Qt5QWindowIcon]", "")
; Confirm to exit.
ControlClick( "sVMS2000", "", $hWnd1, "left", 1, 370, 210 )
Sleep(500)

Func MyLog($text)
    FileWrite('E:\TMGAD0001\mylog.txt', @YEAR&'-'&@MON&'-'&@MDAY&' '&@HOUR&':'&@MIN&':'&@SEC & ' ' & $text & @CRLF) ; append
EndFunc


exit 0

Link to comment
Share on other sites

  • Solution

change

Func MyLog($text)
    FileWrite('E:\TMGAD0001\mylog.txt', @YEAR&'-'&@MON&'-'&@MDAY&' '&@HOUR&':'&@MIN&':'&@SEC & ' ' & $text & @CRLF) ; append
EndFunc

to

Func MyLog($text)
    FileWrite(@ScriptDir & '\mylog.txt', @YEAR&'-'&@MON&'-'&@MDAY&' '&@HOUR&':'&@MIN&':'&@SEC & ' ' & $text & @CRLF) ; append
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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