noobomatic Posted April 3, 2007 Share Posted April 3, 2007 Hi, I'm writing something to collect machine information that I want to be recorded in a file on a server. My desire is for it to be completely transparent to the users. What I would like for the script to do is retry opening the log file after waiting 1 second if it is unsuccessful in opening the file. This is what I've attempted so far. While $file = FileOpen("\\servername\logs\servicepackstatus.csv", 1) = -1 Sleep(1000) WEnd FileWriteLine($file, $field1 & "," & $field2 & "," & $field3 & "," & $field4 & "," & $field5 & "," & $field6 & "," & $timestamp) FileClose($file) Exit I get a file handle error when I test with the file open. Ideally it would probably try for a limited number of attempts (10?). I really appreciate any tips. Link to comment Share on other sites More sharing options...
lod3n Posted April 3, 2007 Share Posted April 3, 2007 (edited) Why don't you just do$file = FileOpen("\\servername\logs\"&@ComputerName&"_servicepackstatus.csv", 2) FileWriteLine($file, $field1 & "," & $field2 & "," & $field3 & "," & $field4 & "," & $field5 & "," & $field6 & "," & $timestamp) FileClose($file) ExitAnd then write another script to dump all of the generated CSVs into one master CSV?Edit: Corrected bug. I still contend that this is the way to do it. Having a large number of machines all try to open a file simultaneously is a bad idea, even if you manage to lock the file open first on each machine. Edited April 3, 2007 by lod3n [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
Developers Jos Posted April 3, 2007 Developers Share Posted April 3, 2007 For $x = 1 to 10 $file = FileOpen("\\servername\logs\servicepackstatus.csv", 1) If $file <> -1 then ExitLoop Next If $x > 10 then ; unable to open... Else ; file opened FileWriteLine($file, $field1 & "," & $field2 & "," & $field3 & "," & $field4 & "," & $field5 & "," & $field6 & "," & $timestamp) FileClose($file) EndIf Exit SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 3, 2007 Developers Share Posted April 3, 2007 $file = FileOpen("\\servername\logs\"&@ComputerName&"_servicepackstatus.csv", 2) = -1This doesn't look right at the end of the line .... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
noobomatic Posted April 3, 2007 Author Share Posted April 3, 2007 For $x = 1 to 10 $file = FileOpen("\\servername\logs\servicepackstatus.csv", 1) If $file <> -1 then ExitLoop Next If $x > 10 then ; unable to open... Else ; file opened FileWriteLine($file, $field1 & "," & $field2 & "," & $field3 & "," & $field4 & "," & $field5 & "," & $field6 & "," & $timestamp) FileClose($file) EndIf Exit Perfect! Thanks! Link to comment Share on other sites More sharing options...
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