Jump to content

_FileWriteLog and multiple writers


 Share

Recommended Posts

Hello friends,

I learned the hard way not to open the same file with multiple filehandles at the same time and try to write to it. (happened on opening the script more than once)

Now the question is: What happens If I have more than one script that tries to write into a logfile with _FileWriteLog()? Will there be data loss or is the function programmed that it will wait until the file wil be closed (from another PC?)?

Any ideas?

Thanks.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Not sure how practical this is, but perhaps the first char of first line in file should be 1 or 0.

1 if the file is in use, and 0 if it is not.

pseudo code

check for 0

if 0 write 1

....write log

....write 0

if 1 wait for 0

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi John,

with this I need to write my own "_FileWriteLog" function, and then I would rather go the way and create a logfile for each PC that runs the script.

But the idea is good. :graduated:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Yes, make your own function, but instead of using an insecure method such as checking the first 0 or 1 which might happen almost simultaneously and still allow both/all access to file, use http://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_CreateFile.htm and set $iShare to 0, this will only allow the first process access, when you rellease the file the next can try... problem will be if logwriting is copious... You will have to solve slowdowns... Maybe just use interprocess comunication to tell the other processes to back off... you could use an exclusive mutex for example... many other options...

[edit] Easiest and secure way, have separate logs.... except, You'll have to sort lines if you want to display them later... still less hassle I think.

/Manko

Edited by Manko
Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

Hey John,

I thought about the separate file as well, and I think this could be the solution:

While FileExists("extrafile")
    Sleep(100)
Wend
FileCreate("extrafile")
FileWrite("original file")
FileDelete("extrafile")

But you'd need to add some errorchecking because 2 PCs could try to create the same file at the same time. :graduated:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
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...