http://qs1969.pair.com?node_id=640870


in reply to Re: How do I test to see if another process is writing to a file (in Windows) (!share)
in thread How do I test to see if another process is writing to a file (in Windows)

Tye,

Thanks for the pointer. This is exactly what I needed. However, I'm having problems using createFile. If I open the file "a.out" in an editor (Textpad or Notepad) and then run the following:

#!/usr/bin/perl -w use strict; use Win32API::File 0.08 qw( :ALL ); my $status = createFile( "a.out", "w ke", "r" ) or die "Can't get exc +lusive access to file: $^E\n"; if ( $status ) { print "Got it!\n"; }
$status is always true. I can't get createFile to "die". Any ideas?

Thanks,
Jay

Replies are listed 'Best First'.
Re^3: How do I test to see if another process is writing to a file (in Windows) (!share)
by tye (Sage) on Sep 25, 2007 at 07:46 UTC

    I guess the interactions are a bit different than my expectations. I get the same results. Worse, once I get the exclusive access, the other process still has the file open for write access but its attempts to write to the file fail.

    So, instead, don't share "r" access and you can tell if anything has the file open at all, it seems.

    - tye        

Re^3: How do I test to see if another process is writing to a file (in Windows) (!share)
by goibhniu (Hermit) on Sep 27, 2007 at 15:47 UTC

    I'm not so sure that having a file in Notepad marks the file in use. I can open the same file over and over again in Notepad. Did you try something with more "bloat" like Word?


    I humbly seek wisdom.