How to tell if a file is being written with Perl running on a Windows 2003 Server

I had a Perl Script that used to run on a Mac platform with no problem.  When I run it on Windows, it always reports the file is stable.  The subroutine below would verify that the file size is the same as it was 10 seconds ago, and consider the file stable.  How can I get this working in Windows?

sub stable
      $solid = "no";
      $sizeof = (stat($File))[7];
      $sizeof2 = (stat($File))[7];

      if ($sizeof == $sizeof2) {
        $solid = "yes";
      else {
        $solid = "no";
      return $solid;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm not sure why your code would not work.  I'd first try changing to "$sizeof[2] = -s $File" and see if that works.
JJSystemsAuthor Commented:
Windows reports the size of the source file immediately, instead of gradually increasing the file size as the file copies.  I'm stumped with this one.
Ah.  I missed that you were copying a file.  I'm pretty sure there are other OS's that do the same thing.

What you need to do is one of:
Copy the file to a temp name (common is to prepend ~ or # or append .tmp) and then rename it to the correct name after the copy.  Then, if the real file exists, it is stable (because the copy was done before the rename).  If you are copying via ftp, some ftp software (such as ncftp) includes this functionality built-in.
Copy a dummy file (named something like <filename>.ready) after copying the real file.  Then check if the .ready file exists rather than checking if the main file is "stable".
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

JJSystemsAuthor Commented:
It's third party software depositing the file.  That's not one of my options.
If you can't modify how the file is copied to the system, there really is no good option.  You can't modify the third party software or have the vendor do so?

The only other suggestion I have is to figure out the longest it takes a file to be fully copied and then double it.  Have the script wait that long after it first sees the file before doing anything with it (and assume it is stable at that point).

The final option I can think of is to switch the system the files are copied to to a different OS.  It's not a good option but it would likely fix your "stable" problem.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JJSystemsAuthor Commented:
Thanks anyway.  I have that in place now as a work around, but I need to find a better solution.
What happens if you try to read the file when the size seems stable but the file is still being written?
Can you detect whether the third party software is still running?
JJSystemsAuthor Commented:
If I try to move it while it is being written, I see an error on the console that the file is in use by another process.
Then would it work to have the perl script try to move it every 10 seconds, and when it succeeds without error it can then tell that it is not being written?
JJSystemsAuthor Commented:
I've got it doing that now (actually 20 seconds) but there are all of those annoying console messages.  
I though for sure there would be a better way.
How is it doing the move?
Can you redirect the console messages?  
Are they on stderr?

If a move generates an error, what does a -w test or a (stat)[3] on the file report?

Rather than a move, can you do a copy or a link?
Suhas .Senior QA ManagerCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: wilcoxon (http:#a40405121)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.