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

Hi all,

This seems like it should be sooooo easy to figure out, but I'm stumped. I recently installed my cgi scripts on a Win XP box (used to be on W2K), and now any place I've called a system command using backticks fails.

Example:

    my $time = `time /t` || die "Time failed: $!\n";

...spits out (in my browser window):

    Time failed: Bad file descriptor

...same applies for `date /t', `echo ...`, etc.

Any help would be appreciated, thanks!!

MB

Replies are listed 'Best First'.
Re: Perl CGI on WinXP - Dos 'bad file descriptor'
by nimdokk (Vicar) on Apr 14, 2005 at 20:19 UTC
    If the script works when you run it at the commandline, it may also be a permissions or path issue. Depending on how the webserver is configured, the "user" that runs the CGI may not know how to find the command "time." I believe those commands are kept down in C:\WINNT\System32 (or something like that) and for security reasons, those paths might not be available to the user running the webservice. Have you looked at the various modules for Time, such as Time::localtime?
Re: Perl CGI on WinXP - Dos 'bad file descriptor'
by sasikumar (Monk) on Apr 14, 2005 at 20:11 UTC
    Hi,
    Try running the script from command line. If it runs perfect then there is something wrong with your configuration of the webserver.

    Let us know the version of perl and the Webserver.
    I have used windows XP earlier i had no such problem. Also try it without /t. Try using system command too.

    Update: Try this. Its a guess that /t is assumed as something different
    $cmd="cmd "."time"." "."/t"; $result=`$cmd`;
    Thanks
    SasiKumar
      The command runs fine from the command line. To clarify, ANY command I place between backticks fails with "Bad file descriptor". Here's a simple example:

      if(defined (my $temp = `cmd.exe /c date /t`)) {<br> print "TEMP = $temp\n";<br> } else {<br> die "Command failed: $!";<br> }</br>

      From the command line this script correctly outputs the date, when running via CGI I get the aformentioned "Bad file descriptor".

      IIS Version: 5.1
      Perl Version: This is perl, v5.8.0 built for MSWin32-x86-multi-thread

      Thanks again for your help with this!

      MB
Re: Perl CGI on WinXP - Dos 'bad file descriptor'
by NetWallah (Canon) on Apr 14, 2005 at 20:18 UTC
    Here is my guess as to why this FAD:

    The "Time" function is embedded into cmd.exe.

    If you run perl from the command line, "cmd" is already running. From CGI, it looks for "time.exe" or time.cmd , which does not exist. Try doing it this way:

    my $time = `cmd /c time /t` || die "Time failed: $!\n";

         "There are only two truly infinite things. The universe and stupidity, and I'm not too sure about the universe"- Albert Einstein

Re: Perl CGI on WinXP - Dos 'bad file descriptor'
by mab (Acolyte) on Jun 23, 2005 at 17:43 UTC
    I'm having a vaguely similar problem. Perhaps what I found might help you out. What i was seeing was that this code snippet would fail with "Bad file descriptor" on XP (works fine on W2K):
    delete $ENV{PATH}; # for taint mode open ( CMD, '/tools/usr/local/wbin/ls.exe / 2>res.txt |' ) || die $!; while ( <CMD> ) { print; } close ( CMD );
    Any of these changes allow the program to run:

    1. remove the redirect of STDERR
    2. remove the delete of the PATH envar
    3. set the PATH (rather than delete it) to
    $ENV{'PATH'} = 'C:/WINDOWS/system32;';
    Yes, this last one is not good and I'm not sure what executable is being run from there or DLL being loaded. (strace for Windows?) Anyway, I know this isn't exactly your problem but maybe it will give you some ideas.

    - Mike