SPUG: Bad file descriptor at .+ line \d+.

Chris Wilkes cwilkes-spug at ladro.com
Wed May 24 13:21:52 PDT 2006


On Wed, May 24, 2006 at 11:37:22AM -0700, JD Brennan wrote:
> Anyone seen an error matching this pattern running a Perl CGI
> on Windows 2003 with IIS 6.0?
> 
> Here's my simple test script: dir.pl
> 
> print "Content-type: text/plain\n\n";
> open(CVS,"dir d:\\Inetpub\\wwwroot\\release_docs |") || die "Can't run dir: $!";
> while (<CVS>) { print "$_"; }
> close(CVS);
> 
> Here's the error I get:
> 
> Can't run dir: Bad file descriptor at D:\Inetpub\wwwroot\safe\bin\dir.pl line 2.

Are you just trying to get a listing of stuff in that directory?

use strict;

my @stuff;
my $dir = "c:/tmp";
opendir (FOO, $dir) || die "bah: $!\n";
@stuff = map { "$dir/$_" } grep { !/^\.{1,2}$/ } readdir(FOO);
close FOO;
foreach (@stuff) {
   printf "%-20s %s\n", $_, getType($_);
}

sub getType {
   my $f = shift();
   return "file" if (-f $f);
   return "directory" if (-d $f);
   return "unknown";
}


More information about the spug-list mailing list