stigma Posted February 18, 2007 Posted February 18, 2007 Hey all, Im trying to make an information bridge between two differnt scripting languages via files. in order to prevent data corruption by an accidental read from a file while its being written to, Im using tow extra .txt files in addition to the actual message file as a sort of makeshift mutex lock. I don't know how many here are any familiar at all with VBscript script, but even if you aren't the code is probably easily understandable. im gonna try posting it here in case anyone can help. I'm thinking a lot of you more experienced programmers have worked with VBscript at some point anyway, so im crossing my fingers the problem im having is that once the VBscript has started to run (the side that is sending out the requested info), it dosn't stop sending new updates even though it shoudl lock itself from access as the last action it does (and only the other script should be unlocking it so that it can move forward and respond again). For some reason it just keeps going instead. I hope someone can spot the bug or logic fault because I've been staring myself blind on this... PS, ignore the use of win32.sleep, just immagine its wscript sleep VBscript (information server) expandcollapse popupwriteLockLine = True readLockLine = True howManyTimes = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") '''''''''''''''TESTTESTTEST'''''''''''''''''''''' On Error Resume Next objFSO.DeleteFile("C:\writelock6.txt") objFSO.DeleteFile("C:\readlock6.txt") On Error GoTo 0 Set writeLockFile = objFSO.OpenTextFile("C:\writelock6.txt", 2, True) writeLockFile.writeLine "true" writeLockFile.Close Set readLockFile = objFSO.OpenTextFile("C:\readlock6.txt", 2, True) readLockFile.writeLine "true" readLockFile.Close while 1 'Try opening writelock until there is no error, and continue if the lock is false Do until writeLockLine = "false" bolWritelockReady = False Do Until bolWritelockReady = True On Error Resume Next Set writeLockFile = objFSO.OpenTextFile("C:\writelock6.txt", 1, True) If Err.Number = 0 Then bolWritelockReady = True End If On Error GoTo 0 Win32.Sleep 50 Loop Do until writeLockFile.AtEndOFStream writeLockLine = writeLockFile.Readline Loop writeLockFile.Close Loop 'Write the data to message file Set locationData = objFSO.OpenTextFile("C:\locationdata6.txt", 2, True) locationData.Writeline getDataA() locationData.Writeline getDataB() locationData.Writeline getDataC() locationData.Writeline howManyTimes locationData.Close Win32.Sleep 10 howManyTimes = howManyTimes + 1 'Changes writelock back into true bolWritelockReady = False Do Until bolWritelockReady = True On Error Resume Next Set writeLockFile = objFSO.OpenTextFile("C:\writelock6.txt", 2, True) If Err.Number = 0 Then bolWritelockReady = True End If On Error GoTo 0 Win32.Sleep 50 Loop writeLockFile.WriteLine "true" writeLockFile.Close Win32.Sleep 50 'Changes readlock back into false bolReadlockReady = False Do Until bolReadlockReady = True On Error Resume Next Set readLockFile = objFSO.OpenTextFile("C:\readlock6.txt", 2, True) If Err.Number = 0 Then bolReadlockReady = True End If On Error GoTo 0 Win32.Sleep 50 Loop readLockFile.Writeline "false" readLockFile.Close Win32.Sleep 50 Wend autoit script (requester/reader of data) expandcollapse popupfunc UpdateLocation2() ;Opens up writelock $writeLockFile = FileOpen("C:\writelock6.txt",2) while $writeLockFile = -1 Sleep(50) $writeLockFile = FileOpen("C:\writelock6.txt",2) WEnd ;~ UpdateTooltip("Opening writelock") FileWriteLine($writeLockFile, "false") If $writeLockFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileClose($writeLockFile) ;Checks for readlock = false and then continues when it sees it change $readLockFile = FileOpen("C:\readlock6.txt",0) while $readLockFile = -1 Sleep(50) $readLockFile = FileOpen("C:\readlock6.txt",0) WEnd If $readlockfile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;~ UpdateTooltip("checking for readlock open") $readLockLine = FileReadLine($readLockFile) while NOT $readLockLine == "false" Sleep(50) $readLockLine = FileReadLine($readLockFile) WEnd FileClose($readLockFile) ;Read the information from the message file ;~ UpdateTooltip("reading message") $locationDataFile = FileOpen("C:\locationdata6.txt",0) while $locationdataFile = -1 Sleep(50) $locationDatakFile = FileOpen("C:\locationdata6.txt",0) WEnd If $locationDataFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $varA = FileReadLine($locationDataFile,1) $varB = FileReadLine($locationDataFile,2) $varC = FileReadLine($locationDataFile,3) $howManyTimes = FileReadLine($locationDataFile,4) FileClose($locationDataFile) ;Turns readlock back on ;~ UpdateTooltip("readlock back on") $readLockFile = FileOpen("C:\readlock6.txt",2) while $readlockFile = -1 Sleep(50) $readLockFile = FileOpen("C:\readlock6.txt",2) WEnd If $readlockfile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($readLockFile, "true") FileClose($readLockFile) EndFunc while 1 UpdateLocation2() ; this is just a function i made myself to show results on the screen... UpdateTooltip("Data is : " & $varA & " , " & $varB & " , " & $varC & " - " & $howManyTimes) Sleep(100) WEnd
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now