Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need a Perl-for-Windows equivalent of the Unix sync command.
Windows XP is too slow when writing to a scsi removable disk.
The disk lights indicate that writing is done, but that is only because Windows has stopped writing to it for the moment. As a result the disk sometimes gets taken out prematurely.
Is there a perl command that will tell Windows to sync all disks?
Note: This has nothing to do with autoflush on a particular file.

Replies are listed 'Best First'.
Re: Windows equivlanet of Unix sync
by ysth (Canon) on Nov 25, 2004 at 21:05 UTC
Re: Windows equivlanet of Unix sync
by BrowserUk (Patriarch) on Nov 25, 2004 at 21:52 UTC

    Try this. No guarentees as it is quite hard to contrive a test scenario.

    Adjust the drive letter in the call to createFile() to suit.

    #! perl -slw use strict; use Win32API::File; ## Hacked to export everything use Win32::API::Prototype; ApiLink 'Kernel32', q[BOOL FlushFileBuffers( HANDLE hFile )] or die $^E; my $devHandle = createFile( '//./C:', 'wke' ); $devHandle == -1 and die $^E; FlushFileBuffers( $devHandle ) or die $^E;

    Examine what is said, not who speaks.
    "But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
    "Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo         "Efficiency is intelligent laziness." -David Dunham
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon