Jump to content

Restarting a process after checking a log file


Jijo
 Share

Recommended Posts

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 ?

Link to comment
Share on other sites

  • Moderators

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

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

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

Link to comment
Share on other sites

  • Moderators

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

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

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