Jump to content

If file .txt change, close .exe?


Joshjosh
 Share

Recommended Posts

I wish to have an exe running that monitors a files, say "a.txt", time/date stamp. If it changes, close/kill the process iexplore.exe

This similar to what was done earlier in another thread where I restarted a service instead of killing the exe but this is for a different task.

Attached is the restart service script ("Music"), along with my "attempt" ("ProcessClose") at changing the action part but get script errors. If anyone could anyone help me out, it would be much appreciated.

Music.au3

ProcessClose.au3

Edited by Joshjosh
Link to comment
Share on other sites

I think you are overthinking it.

$file = "file.txt"
$lastModified = FileGetTime ($file, 0, 1)

While 1
    If $lastModified <> FileGetTime ($file, 0, 1) Then SomeFunction()
    Sleep(10)
WEnd

Func SomeFunction()
EndFuncoÝ÷ ÚÚºÚ"µÍÌÍÙ[HH ][ÝÙ[K    ][ÝÂÌÍÛÝ[ÙYYYH[QÙ][YH
    ÌÍÙ[KJBÂÛY
L
B[[ ÌÍÛÝ[ÙYYY  ÉÝÈ[QÙ][YH
    ÌÍÙ[KJBÛÛYQ[Ý[Û
B[ÈÛÛYQ[Ý[Û
B[[
Edited by weaponx
Link to comment
Share on other sites

I wish to have an exe running that monitors a files, say "a.txt", time/date stamp. If it changes, close/kill the process iexplore.exe

This similar to what was done earlier in another thread where I restarted a service instead of killing the exe but this is for a different task.

Attached is the restart service script ("Music"), along with my "attempt" ("ProcessClose") at changing the action part but get script errors. If anyone could anyone help me out, it would be much appreciated.

There are a couple of things wrong in the sample

1) No WEnd to close the loop (typo?)

Easier way is

Global $on_start_value = FileRead($file_to_monitor)

While 1
   If FileRead($file_to_monitor) <> $on_start_value Then
      If ProcessExists("iexplore.exe") Then ProcessWaitClose($iexplore.exe)
      Do whatever else
   EndIf
   Sleep (1000)
Wend

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

So more along these lines (Icould be wrong as I'm only very new to scripting):

Global $file_to_monitor = "C:\a.txt"

Global $on_start_value = CheckForFileUpdate($file_to_monitor)

While 1

Sleep(1000)

$return_date = CheckForFileUpdate($file_to_monitor)

;ConsoleWrite(@CRLF & $return_date & " - " & $on_start_value)

If $return_date <> $on_start_value Then

_ProcessClose() ;

$on_start_value = $return_date ; resets the on_start_value to newest date / time value

Func CheckForFileUpdate($file_to_check)

$file_time = FileGetTime($file_to_check, 0)

If Not @error Then

$yyyymd = $file_time[0] & "/" & $file_time[1] & "/" & $file_time[2]

$hhmmss = $file_time[3] & ":" & $file_time[4] & ":" & $file_time[5]

Return $yyyymd & " " & $hhmmss

EndIf

Return 0

EndFunc ;==>CheckForFileUpdate

Func _ProcessClose()

Local $time1, $time2

Global $on_start_value = FileRead($file_to_monitor)

While 1

If FileRead($file_to_monitor) <> $on_start_value Then

If ProcessExists("iexplore.exe") Then ProcessWaitClose($iexplore.exe)

Do whatever else

EndIf

Sleep (1000)

Wend

EndIf

$time1 = TimerInit()

Do

Sleep(1000)

EndIf

Return "0"

EndFunc ;==>_ProcessClose

Thanks for all your help and fast replies.

Edited by Joshjosh
Link to comment
Share on other sites

my bad. So the script is ok, just get rid of the checkforfileupdate paragraph

Global $file_to_monitor = "C:\a.txt"

Global $on_start_value = CheckForFileUpdate($file_to_monitor)

While 1

Sleep(1000)

$return_date = CheckForFileUpdate($file_to_monitor)

;ConsoleWrite(@CRLF & $return_date & " - " & $on_start_value)

If $return_date <> $on_start_value Then

_ProcessClose() ;

$on_start_value = $return_date ; resets the on_start_value to newest date / time value

Global $on_start_value = FileRead($file_to_monitor)

While 1

If FileRead($file_to_monitor) <> $on_start_value Then

If ProcessExists("iexplore.exe") Then ProcessWaitClose($iexplore.exe)

Do whatever else

EndIf

Sleep (1000)

Wend

EndIf

$time1 = TimerInit()

Do

Sleep(1000)

EndIf

Return "0"

EndFunc ;==>_ProcessClose

Link to comment
Share on other sites

The code you posted isn't valid. You should run Tidy in SciTE before posting, there were like 5 errors. It also might help if you explained the goal of the script because the code is more complex than it needs to be.

Link to comment
Share on other sites

Ok so I have Internet Explorer opening a htm on the local hard drive. This html has an embedded flash object. I periodically update the flash and html file via ftp at which time I want internet explorer to close as there is a separate process that monitors when IE closes and automatically reloads it. It sounds odd but its for a display pc in a shop window.

Link to comment
Share on other sites

Ok so I have Internet Explorer opening a htm on the local hard drive. This html has an embedded flash object. I periodically update the flash and html file via ftp at which time I want internet explorer to close as there is a separate process that monitors when IE closes and automatically reloads it. It sounds odd but its for a display pc in a shop window.

If you're doing the update then what's the problem? You already know when the file is updated. Just send F5 to refresh the page in IE.

EDIT: What app are you using to FTP the file?

Most FTP apps that I've used have an Exit when finished function So when the FTP process ends Send F5

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

correct weaponx. There will be roughly 50 display PC's around the country with a user in the head office making changes to the flash. He will be updating the music and flash content periodically which is then rolled out via a FTP app. At the moment a refresh command is built into the html code however theres always the off chance that the second he is uploading a file, the page refreshes and gets a page not found.

The music code I posted works perfectly. He uploads songs xyz and updates the file playlist.txt. The script finds the time date stamp and restarts the service that is bound to running the MP3 files via a command line.

So all I really want to do is change the action from restart service to kill/end iexplore.exe as there is another script that monitors any time iexplore ends, reopen it.

Sorry for the miscommunication above, I'm only very new to scripting and need to read up on a few helpfiles and books.

Cheers

Link to comment
Share on other sites

It sounds like he will be updating the FTP site from home, and the one in the display will be constantly monitoring the ftp site for changes tothe files.

This looks like one for Dale'

I think there are functions in the ie.au3 file that will allow him to check for code changes in the file on the server. If that code changes then refresh the browsers in the other locations. Again {F5} will do that part. You don't have to close the browsers that way.

Really the simplest method is to add

<meta http-equiv="refresh" content="3600">

to the <head> section of the HTML

That will force the page to refresh every hour. To change the refresh rate change the content= and set a different interval in seconds.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I think I would write a small script that would run on each of the remote systems to manage this. There would be several approaches that you could use depending on how responsive you want or need to be to changes in the displayed files.

You can also attach to IE instances over the network from a central location -- there would need to be quite a lot of error checking and fault adjudication added if you went this way however.

In the local script approach, here is one very simplistic approach. It creates a browser at your url (or attaches to one if it already exists). It then refreshes once per hour and checks for display errors... if there are display errors it tries to redisplay the URL until they clear up (if you don't get a 404 File Not Found error, you'll need to adjust the text).

$oIE = _IECreate("your-url", 1)

While 1
    Sleep(360000)
    _IEAction($oIE, "refresh")
    While DisplayErrors()
        _IENavigate($oIE, "your-url")
        Sleep(1000)
    Wend
Wend

Func DisplayErrors()
    $sContent = _IEDocReadHTML($oIE)
    If StringInStr($sContent, "File Not Found") Then 
        Return 1
    Else
        Return 0
EndFunc

Using this kind of a setup you can also check the create date of the files that you are displaying, store it and then continually check for updates. Then trigger the Refresh action or an _IENavigate when you note a change.

Again, there are many ways to approach this and your decisions will depend on your situation specifics.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Hey Dale,

Thanks for the information. My only concern is if the client by chance uploads the files at the exact same time as they attempt to upload, the page cannot load. Now as the flash file is a few Mb, I have seen the case where the file is uploading, the IE page refreshes (which the flash file is embedded in), the flash file cannot be loaded as it is still uploading, so there is just a blank white page. This means that the above script won't work on the 404 or page not found front as there is no text displayed as the html page loads find, its just content that doesn't.

I think the best way is still the orginal I listed, except change the action from restart service to close iexplore.exe. If we can get that far, I ca ntake care of the rest (i.e. reloading IE after a closeure, confirming content is up...).

All of your help and suggestions have been much appreciated. This is one of the very few forums where people are eager help, a nice change.

Thanks

Josh

Link to comment
Share on other sites

finalllly got it sorted. amazing what you learn when forced to. I was completely over complicating it as mentionned above. I ripped the whole action component out and started it fresh using the help to guide me and it now works a treat.

I now have 2 scripts that run all the time. One monitors for iexplore.exe and if its closed (i.e. a user tries to user the mediapc as a workstation and closes ie), it will automatically open again and lock the mouse cursor off screen (remembering all this box does is run a full screen html page embedded in flash). The second is this one. When we upload the new content (xyz.html and xyz.swf) via ftp from a remote server, this script monitors to c:\xyz\xyz.htm and automatically closes the iexplore session. The other session immediately reopens iexplore with the new content.

I know this sounds odd, but it is better than have a refresh time built into the html code as there is always the chance the page refreshes while doing a upload and rendering a page not found or blank page (cant find ebedded swf as it will be in use).

Thanks again for everyones help and hope these little scripts can help others in the future.

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