Sign in to follow this  
Followers 0
knarfin

File access issue

9 posts in this topic

I'm trying to read a log file as it's being updated by another program. The log file is being written to 2x per second, and the script read it 2x/sec. Right now the script will read it once, and the file will cease to be written to until the script is closed. I've followed all the FileOpens with FileCloses, but it seems like the script freezes the file's access as long as it's running. Ideas?

CODE
$Log = "C:\myLog.log"

$LineReadA = 0

While 1

$nMsg = GUIGetMsg()

Do

$nMsg = GUIGetMsg()

If $nMsg = $GUI_EVENT_CLOSE

Exit

EndIf

$RealSec = @SEC

Sleep(1)

$RealSec2 = @SEC

Until $RealSec2 > $RealSec

$LineReadB = $LineReadA

$FileRead = FileOpen($Log,0)

$LineReadA = FileReadLine($FileRead, -1)

FileClose($Log)

GUICtrlSetData ($LastLine, $LineReadA)

WEnd

Share this post


Link to post
Share on other sites



@all

Can this get you going ?

; In computer programming, a mutex (mutual exclusion object) is a program object that is created so that multiple program thread

; can take turns sharing the same resource, such as access to a file. Typically, when a program is started, it creates a mutex for a

; given resource at the beginning by requesting it from the system and the system returns a unique name or ID for it. After that,

; any thread needing the resource must use the mutex to lock the resource from other threads while it is using the resource.

; If the mutex is already locked, a thread needing the resource is typically queued by the system and then given control when the mutex

; becomes unlocked (when once more, the mutex is locked during the new thread's use of the resource).

Func _CreateMutex($sOccurName)
    $hMutex = DllCall("kernel32.dll", "hwnd", "CreateMutex", "int", 0, "int", 1, "str", $sOccurName)
    $hMutex = $hMutex[0]
    If $hMutex = 0 Then Exit
EndFunc

Func _Write()
    FileWriteLine("c:\write.txt", GUICtrlRead($input))
    DllCall("kernel32.dll", "int", "ReleaseMutex", "hwnd", $hMutex)
    DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hMutex)
    $hMutex = 0
EndFunc

Regards,

Ptrex

Share this post


Link to post
Share on other sites

That leads me in the right direction; thanks.

The problem is that another application is creating and writing to/reading from the log file. After looking at the CreateFile entry in the MSDN library, it seems like the share attributes have to be set upon file creation (which I have no control over). Is there a way to modify the file access sharing modes of existing files?

Share this post


Link to post
Share on other sites

ohhhhhh. Yes, I see now. I have it returning text characters using the _WinAPI functions, but I now I need a way to locate the byte locations of the beginning and end of lines in the log, so I can extract one line of text at a time. The UDFs I've seen on here use FileOpen, CountLines, etc, to retrieve this information, which apparently don't allow for access sharing.

Share this post


Link to post
Share on other sites

It would work with FileOPen, too., but FileClose needs the HANDLE, not the Filename :P

$FileRead = FileOpen($Log,0)

$LineReadA = FileReadLine($FileRead, -1)

FileClose($FileRead)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

dummmmmmmb. And it works. THANK YOU!

Share this post


Link to post
Share on other sites

dummmmmmmb. And it works. THANK YOU!

no question is dumb to ask

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  
Followers 0