Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

df sometimes hangs in Win32 OS

by Dandello (Scribe)
on Sep 22, 2012 at 16:28 UTC ( #995108=perlquestion: print w/ replies, xml ) Need Help??
Dandello has asked for the wisdom of the Perl Monks concerning the following question:

Yeah, the title is cryptic.

The problem (we think) is in here

my @disk_space = qx{df -k .}; map { $_ =~ s/ +/ /g } @disk_space;

It works fine to check the available disk space on *nix servers. But occasionally - just occasionally - it brings up command windows when executed on servers (Apache or IIS) running XP or Win 2003 and stops the script the code is in from working properly.

I read that there are better ways of writing qx{df -k .}; and having a Win32 compatible method of checking disk space would be nice.

The current work around is simply to not run this section of code when the OS is MSWin32. But there has to be a better way.

(I didn't write this code, I'm just in the process of debugging it.)

Comment on df sometimes hangs in Win32 OS
Select or Download Code
Re: df sometimes hangs in Win32 OS
by roboticus (Canon) on Sep 22, 2012 at 17:56 UTC

    Dandelio:

    I'd suggest using Win32::DriveInfo for windows machines.

    Update: Fixed cpan link.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: df sometimes hangs in Win32 OS
by BrowserUk (Pope) on Sep 22, 2012 at 18:13 UTC

    I'd use fsutil on windows:

    C:\test>fsutil volume diskfree . Total # of free bytes : 89573777408 Total # of bytes : 627247673344 Total # of avail free bytes : 89573777408

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      So, what I think is being said is that the script this is in needs an OS checker so it can load a Win32 specific utility to do the job?

      The script needs to be cross-platform. 95%+ of the installations are on *nix. Maybe 5% of the Win installs come up with this problem. So it's a pretty rare issue.

        So, what I think is being said is that the script this is in needs an OS checker so it can load a Win32 specific utility to do the job?

        I have a df utility on my windows system -- part of the UnxUtils package though it segfaults on my 64-bit OS -- but generally most windows systems will not have it, and expecting users to find and install one is naive.

        Far simpler I think to use something like:

        sub freespace { if( $^O eq 'MSWin32' ) { `fsutil volume diskfree .` =~ m[avail free bytes : (\d+)]; return ( $1 // die $! ) / 1024; } elsif( $^O eq ... ) { ... } else { `df -k .` =~ m[...]; return $1 // die $! } } ... my $free = freespace();

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

        div class=

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://995108]
Approved by bulk88
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-09-17 01:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (56 votes), past polls