tim.mcintosh has asked for the wisdom of the Perl Monks concerning the following question:

We have a legacy system that uses Perl for the glue. The system generates .bat files in a CGI environment and then uses the SYSCALL of Perl to execute the.bat files and pipe them into a .txt file that can be reviewed in the CGI environment to watch them run and ensure successful execution.

The system has relied on the following code running on Windows Server 2000 for years -->

$hldcmd = "$pathcc" . "\\" . "$hldbat" . " \> " . "$pathcc" . "\\" . +"$txtname" . ".txt"; open(SYSCALL, "$hldcmd |");

We are moving to Windows Server 2003 Release 2 SP 2 and the system calls do not work. Is this a known issue? If so are there work arounds. Please note I have no controll over the environment.

Thanks Tim

Replies are listed 'Best First'.
Re: Perl SYSCALL
by moritz (Cardinal) on Oct 26, 2009 at 22:08 UTC

    That's just a normal call to open that tries to open a pipe.

    In what way does it not work? You should emit error messages like this:

    open SYSCALL, "$hlcmd |" or die "Can't start '$hlcmd': $!";

    That way you have a chance to find out what's wrong when it doesn't work.

    Perl 6 - links to (nearly) everything that is Perl 6.
      It might be worth pointing out that the error message will appear in the web server error log and not in the browser, unless there's some magic in place.

      -- Time flies when you don't know what you're doing
      Gentlemen, and Ladies,

      I am running Perl 5.8.3 that is the Windows Perl embedded with Oracle 10g DBMS during the Oracle installion. Admittely, I am dangerous with Perl as it was so painfully pointed out, but, I need to fix the problem.

      Based on replies I changed the code as follows to trap an error.

      $hldcmd = "$pathcc\\$hldbat > $pathcc\\$txtname.txt";
      open SYSCALL, "$hldcmd |" or die "Requested submit failed -> $hlcmd: $!";

      I received the following error message on the browser->

      Software Error:
      Requested submit failed -> , Bad file descriptor at C:\Inetpub\pmmproot\cgi-bin\viewbat.pl line 255 (this is the SYSCALL line above).
      For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
      Tue Oct 27 09:39:29 2009 viewbat.pl: Requested submit failed -> , Bad file descriptor at C:\Inetpub\pmmproot\cgi-bin\viewbat.pl line 255.

      I checked the paths/names and they look good. The variables translate to the following values:

      pathcc - C:\inetpub\pmmproot\pmmpcc
      hldbat - B1MSN10232009104615.BAT
      txtname - B1MSN10232009104615
      submit - C:\inetpub\pmmproot\pmmpcc\B1MSN10232009104615.BAT > C:\inetpub\pmmproot\pmmpcc\B1MSN10232009104615.txt

      I took the value in submit and ran it in DOS and it worked. So I am more confused.

      I certainly appreciate you taking the time but I am not sure what to look at next.

      Thanks Tim

        Try using the system() builtin function. As you are redirecting the output of the batchfile to a file, there is no point in opening a pipe from that batch to your script.

        If it doesn't help try to execute "$ENV{ComSpec} $pathcc\\$hldbat > $pathcc\\$txtname.txt".

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.

Re: Perl SYSCALL
by Jenda (Abbot) on Oct 27, 2009 at 09:17 UTC

    Ouch!

    $hldcmd = "$pathcc\\$hldbat > $pathcc\\$txtname.txt";
    Ain't this easier?

    And never ever (unless you really know why) write ... "$varname" .... The quotes are not necessary, this is not shell script! They confuse things and waste resources.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

SYSCALL - followup 1
by tim.mcintosh (Initiate) on Oct 27, 2009 at 15:17 UTC
    Perl Monks,

    Based on replies I changed the code as follows to trap any error.

    $hldcmd = "$pathcc\\$hldbat > $pathcc\\$txtname.txt";
    open SYSCALL, "$hldcmd |" or die "Requested submit failed -> $hlcmd: $!";

    I received the following error message on the browser->

    Software Error:
    Requested submit failed -> , Bad file descriptor at C:\Inetpub\pmmproot\cgi-bin\viewbat.pl line 255 (this is the SYSCALL line above).
    For help, please send mail to this site's webmaster, giving this error message and the time and date of the error. Tue Oct 27 09:39:29 2009 viewbat.pl: Requested submit failed -> , Bad file descriptor at C:\Inetpub\pmmproot\cgi-bin\viewbat.pl line 255.

    I checked the paths/names and they look good. The variables translate to the following values:

    pathcc - C:\inetpub\pmmproot\pmmpcc
    hldbat - B1MSN10232009104615.BAT
    txtname - B1MSN10232009104615
    submit - C:\inetpub\pmmproot\pmmpcc\B1MSN10232009104615.BAT > C:\inetpub\pmmproot\pmmpcc\B1MSN10232009104615.txt

    I took the value in submit variable above and ran it in DOS and it worked. So I am more confused.

    I certainly appreciate you taking the time but I am not sure what to look at next.

    Thanks Tim

      What do you want to do, actually?

      You're trying to run the following command (with the variable names interpolated):

      $pathcc\\$hldbat > $pathcc\\$txtname.txt" |

      Maybe you don't want to have the pipe at the end? Maybe you're unaware of qx and system?

      Also, there is little need to create a new root node if all you're doing is continue your original post. You could have at least linked to your previous post so somewhat more context was provided.

      I'm gonna guess that if the same code works on the command line but not when run as a CGI, the environment is different when run as a CGI. This is fairly common, as the CGI environment is more prone to Naughty People trying to break things so is set up to be paranoid.

      Here's a little perl script you can run as a CGI to spit out a copy of the environment, for comparison with what you get at the command prompt.

      #!/usr/bin/perl print "Content-type: text/html\n\n"; print "<HTML><BODY>"; print "<TABLE><TR><TH>Environment variable</TH><TH>Value</TH></TR>"; foreach (sort keys %ENV) { print "<TR><TH ALIGN=RIGHT>$_:</TH><TD>$ENV{$_}</TD></TR>"; } print "</TABLE>"; print "</BODY></HTML>";

      You also need to be aware that the web server would normally run as a seperate user, so may have different permissions to what you do. To investigate whether you have the right permissions on the various files you need access to, see perldoc -f -r.