Jump to content
Sign in to follow this  
Jijo

Restarting a process after checking a log file

Recommended Posts

Jijo

I want to restart a process by checking a log file "C:\Documents and Settings\~\Desktop\New Folder\test.txt", so I have copied some code from this forum and created an immature script. But now I want to read a log file like "C:\Documents and Settings\~\Desktop\New Folder\test_yyyymmdd.txt" where yyyymmdd is year month and date (like 20110927). I have searched a lot but couldn't find anything what exactly required for me.

#include <Date.au3>

Local $TempFileDate = FileGetTime( "C:\Documents and Settings\~\Desktop\New Folder\test.txt", 0 )

Local $JobLastRun = $TempFileDate[0] & "/" & $TempFileDate[1] & "/" & $TempFileDate[2] & " " & $TempFileDate[3] & ":" & $TempFileDate[4] & ":" & $TempFileDate[5]

if _DateDiff("s", $JobLastRun, _NowCalc()) >60 Then

$PID = ProcessExists("notepad.exe") ; Will return the PID or 0 if the process isn't found.

If $PID Then

ProcessClose($PID)

EndIf

Run("notepad.exe")

EndIf

Could you please help me ?

Share this post


Link to post
Share on other sites
Melba23

Jijo,

Welcome to the AutoIt forum. :graduated:

I think this should do what you want:

#include <Date.au3>

; Write an initial log file
FileWrite(@ScriptDir & "\test.txt", "fred")

While 1

    Local $TempFileDate = FileGetTime(@ScriptDir & "\test.txt", 0)

    Local $JobLastRun = $TempFileDate[0] & "/" & $TempFileDate[1] & "/" & $TempFileDate[2] & " " & $TempFileDate[3] & ":" & $TempFileDate[4] & ":" & $TempFileDate[5]

    If _DateDiff("s", $JobLastRun, _NowCalc()) > 10 Then

        $PID = ProcessExists("notepad.exe") ; Will return the PID or 0 if the process isn't found.
        If $PID Then
            ; Close the process
            ProcessClose($PID)
            ; Wait until process has closed
            While ProcessExists($PID)
                Sleep(10)
            WEnd
            ; Reopen the process
            Run("notepad.exe")
            ; Wait until it opens
            ProcessWait("notepad.exe")
            ; Rewrite the log file
            FileWrite(@ScriptDir & "\test.txt", "fred")
            ; Allow time for sytem to catch up
            Sleep(100)
        Else
            ; Open the process initially
            Run("notepad.exe")
            ; As above
            ProcessWait("notepad.exe")
            FileWrite(@ScriptDir & "\test.txt", "fred")
            Sleep(100)
        EndIf

    EndIf

WEnd

I changed the logfile path for testing - you will have to change it back. :)

Please ask if anything is unclear. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Jijo

Hi Melba23,

Thanks for the updated code. I will check this today and if there is anything not clear then surely I will request your help.

Jijo

Share this post


Link to post
Share on other sites
Jijo

Hi Melba23,

how I can read a filename "C:\Documents and Settings\~\Desktop\New Folder\test_<<yyyymmdd>>.txt" where yyyymmdd changes daily. And how I can check its update time?

The previous requirement was completed. Thanks for your help.

Jijo

Share this post


Link to post
Share on other sites
Melba23

Jijo,

Create the filename like this - not sure if you want today or any given date so I have shown how to do both: ;)

$sYear = "1984"
$sMon  = "05"
$sDay  = "17"

$sFileName = "C:\Documents and Settings\~\Desktop\New Folder\test_<<" & $sYear & $sMon & $sDay & ">>.txt"

ConsoleWrite($sFileName & @CRLF)

$sFileName = "C:\Documents and Settings\~\Desktop\New Folder\test_<<" & @YEAR & @MON & @MDAY & ">>.txt"

ConsoleWrite($sFileName & @CRLF)

and then use FileRead($sFileName).

how I can check its update time?

You used FileGetTime in the other script - why not use it again? :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Jijo

Hi Melba23,

Actually the second one suffice .. Thanks alot for your response.

Jijo

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  

×