I have a Perl application that writes logs to a file using open and print calls.
open (FH, "d:\\temp.txt");
print FH "Some log";
close (FH);
However, with a sharp shutdown of the machine, the logs are not saved in the file. Therefore, after searching in several places, two options were proposed for performing unbuffered I / O (for example, for writing text to disk, and not for saving it in the cache, and then for cleaning it):
I tried both of these options and it just doesn't work. Any entry I make seconds before abnormal shutdown is lost.
Is there a way that I can almost deterministically perform unbuffered I / O in Perl? I am using the 64-bit version of Windows 7 with Perl 5.8.3.
EDIT: I was looking for how to make windows without I / O buffering, and here's how to do it! Call
- CreateFile with FILE_FLAG_NO_BUFFERING for the dwFlagsAndAttributes parameter. However, these are memory alignment issues to consider (for example, file access buffers must be sector-aligned; the application determines the sector size by calling GetDiskFreeSpace )
- Use WriteFile to write data to a file. This record will be unbuffered and instead of going to the cache, it immediately goes to disk.
- Finally, call FlushFileBuffers to clear the metadata associated with the files.
Maybe someone can help using the Win32 API with Perl for these 3 calls.