I have the below script which is working fine on cmd line, but nothing gets displayed on browser. There is no permission issue. If i remove the open statement and print some other data. Its working fine on browser. Kindly help.
#!c:/perl/bin/perl
use Win32::ODBC;
use CGI ':standard';
print "Content-type: text/html\n\n";
print '<HTML>';
print '<HEAD>';
print '<link rel="stylesheet" type="text/css" href="../user_tabs.css" />';
print '<TITLE>Local User Accounts</TITLE>';
print '</HEAD>';
print '<BODY>';
print '<TABLE BORDER="2" FRAME="BOX" RULES="ALL">';
print '<TR><TH><FONT FACE ="ARIAL" SIZE="2">User ID</TH><TH><FONT FACE ="ARIAL" SIZE="2">Hosts</TH></TR>';
my $line;
my @line2;
my @line3;
my %hosthash;
my @templine;
my @acc_user;
my @host_name;
my $count=0;
my $count1=0;
my $check;
my $check2;
my @hostname;
my @filedata;
my $ldapuser;
open(FILE,"somefile.txt") or die("Unable to open file");
foreach $line3 (<FILE>)
{
chomp($line3);
push(@filedata,$line3);
}
close(FILE);
foreach $line (@filedata)
{
chomp($line);
@templine=split(/,/ ,$line);
$count=0;
$hosthash{$templine[0]} = [] unless exists $hosthash{$templine[0]};
foreach $check(@acc_user)
{
if($check eq $templine[0])
{
$count=1;
last;
}
}
if($count==0)
{
push(@acc_user,$templine[0]);
}
foreach $check2(@acc_user)
{
if($check2 eq $templine[0])
{
push @{ $hosthash{$check2} }, $templine[1];
#print "Plesae wait Loading Data \n";
}
}
}
foreach $ldapuser(@acc_user)
{
@hostname = @{$hosthash{$ldapuser}};
print "<TR><TH><FONT FACE =ARIAL SIZE=2>"."$ldapuser"."</TH><TH><FONT FACE =ARIAL SIZE=2>"."@hostname"."</TH></TR>";
}
print '</TABLE>';
print '</BODY>';
print '</HTML>';
---------- Post updated at 02:06 PM ---------- Previous update was at 02:04 PM ----------
try open(STDERR, ">&STDOUT"); after you import your modules to redirect error messages out of standard error and into stdout where they should appear on your browser.
It's annoying that even redirecting STDERR doesn't get you the error messages! It's probably trying to tell you what you're doing wrong but the message floats off into hyperspace...
I suspect it's not actually able to open the file due to either some difference in path or some difference in permissions. The perl scripts may be getting run under a different user than you. Try putting your datafile under something like C:\Documents and Settings\All Users\Documents\ where permissions are more relaxed. Check the logs for your webserver, see if it's logging the error output anywhere.
How's the output look running from the command prompt?
Maybe try added a newline at the end. Also, I know \n\n works but I believe \r\n\r\n to be more standard and was required for me on one webserver (though my CGI was in bash).
What makes you think the file has correct permissions when it never works from anything but your own user? Did you actually try moving it to where I suggested?
open(STDERR, ">&STDOUT");
This should be BEFORE the other open, so you can see its error message.