in reply to Perl SYSCALL

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

Replies are listed 'Best First'.
Re: SYSCALL - followup 1
by Corion (Patriarch) on Oct 27, 2009 at 15:22 UTC

    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.

Re: SYSCALL - followup 1
by DrHyde (Prior) on Oct 27, 2009 at 15:52 UTC

    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.