in reply to Unable to write to a file opened in read only mode
Okay, I finally got a chance to test this under WinNT... and I got the same results I got under Win2K. With a file open for read-only access in Perl, notepad and gvim don't care in the least and will still open, edit, and save the file.
It is nice that several people have chimed in with how "this is just how Windows works", but I don't believe any of them. (: I've certainly seen cases where shared access was denied when I had hoped that it wouldn't be, but a quick test shows that this isn't such a case.
It is true that, unlike Unix, Windows gives you the option of requesting that no other program do certain things to the file while you are using it and of having that request enforced by the operating system (not requiring all tasks dealing with the file to cooperate nor requiring special tagging of the file to get this).
It is also true that many Windows programs, especially those not written in C, chose to request no sharing when they open files (or at least less sharing than you sometimes would like).
The details are that you can request three types of sharing: read, write, and delete. ("Delete" sharing doesn't apply prior to WinNT.) You specify zero or more of these types of sharing be allowed whenever you open a file in Windows. When using C code, the default is to request only "read" and "write" sharing.
If you don't request "read" sharing, then you won't be able to open the file if anyone else has the file open for reading and once you have the file open, nobody else will be allowed to open it for reading. "write" sharing is exactly the same except you replace "reading" with "writing".
See Win32API::File for some more information on this and how to use Perl to play with opening files specifying different types of sharing.
- tye (but my friends call me "Tye")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: Unable to write to a file opened in read only mode
by cgrinder (Initiate) on Nov 05, 2001 at 19:58 UTC |