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

Jacinta Richardson jarich at perltraining.com.au
Wed May 24 16:11:24 PDT 2006


On Wed, 24 May 2006, 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.
> 
> Script works on another Windows 2003 box with IIS 6.0.  I can't find how
> I've got them configured differently.

My theory is that your environments are different.  It is possible that
on the machine that's failing, "dir" isn't in the path.  You can test this
by changing your script to:

	print "Content-type: text/plain\n\n";
	system("dir d:\\Inetpub\\wwwroot\\release_docs");
	if($?) {
		"Failed to run dir: $!";
	}

The solution would be to set $ENV{PATH} to something which includes the
location of your "dir" executable - have a look at what the working
machine has in it's PATH.  I think you can just type "env" at the dos
prompt to see all the values (or loop over the keys of %ENV).

For what it's's worth, I strongly recommend using the three argument
version of open for piped commands.  (Unless you need backwards
compatibility with Perl < 5.6.0).

 	open(CVS, "-|", "dir d:\\Inetpub\\wwwroot\\release_docs") 
		or die "Can't run dir: $!";

This makes it much more clear to others that you don't want to open the
filename: "dir d:\\Inetpub\\wwwroot\\release_docs |" but are actually
executing a command (or if they don't know the syntax, at least they
realise you're doing something that looks odd).

All the very best,

	Jacinta

--
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |  
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
(il),-''  (li),'  ((!.-'              |   www.perltraining.com.au   |



More information about the spug-list mailing list