Nothing is getting displayed on browser while using open statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nothing is getting displayed on browser while using open statement
# 1  
Old 06-22-2011
Nothing is getting displayed on browser while using open statement

Hi,

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.
Code:
#!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 ----------

Only

User IDHosts is getting displayed on browser

Last edited by Franklin52; 06-22-2011 at 04:25 PM.. Reason: Please use code tags
# 2  
Old 06-22-2011
Use the absolute path for the file. Your current directory is probably different when called by CGI.
Code:
open(FILE,"c:/path/to/somefile.txt") or die("Unable to open file");

or maybe c:\\path\\to... depending on how windows paths in Perl work.
# 3  
Old 06-22-2011
Thanks, but it is still not working Smilie
# 4  
Old 06-22-2011
Can you get a minimal perl script to work?

Code:
#!c:/perl/bin/perl

print "Content-type: text/plain\n";
print "\n";

print "This is a message\n";

---------- Post updated at 12:39 PM ---------- Previous update was at 12:36 PM ----------

Also, you can try open(STDERR, ">&STDOUT"); to redirect error messages out of standard error and into stdout where they should appear on your browser.
# 5  
Old 06-22-2011
Yes. If i remove the open statement and pring some thing else. Its working.

For example the below script.
Code:
#!c:/perl/bin/perl
use Win32::ODBC;
use CGI ':standard';
print "Content-type: text/html\n\n";
 
print '<HTML>';
print '<HEAD>';
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">Number</TH><TH><FONT FACE ="ARIAL" SIZE="2">Factorial</TH></TR>';

my $i;
my $j;
my $prod;
for($i=1;$i<=20;$i++)
{
 $prod=1;
 for($j=i;$j>=1;$j++)
 {
  $prod=$prod*$j;
 }
 print '<TR><TH><FONT FACE ="ARIAL" SIZE="2">'."$i".'</TH><TH><FONT FACE ="ARIAL" SIZE="2">'."$prod".'</TH></TR>';
}
print '</TABLE>';
print '</BODY>';
print '</HTML>';

prints

NumberFactorial112131415161718191101111121131141151161171181191201

on the browser

Last edited by Franklin52; 06-22-2011 at 04:27 PM.. Reason: Use code tags for data and code samples
# 6  
Old 06-22-2011
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.
# 7  
Old 06-22-2011
No luck
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

0403-016 Cannot find or open the file in If Statement

Hi, I am comparing the number of records in the .bad record from sql loader, if it is higher than the number passed in as an argument, the program should exit. However, I constantly receive the error " 0403-016 Cannot find or open the file." on the line with the if statement "elif ;". The code... (3 Replies)
Discussion started by: MIA651
3 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Solaris

Can't open netscape web-browser

I am working in solaris 9 and i want to work with web-browser(netscape). but when I am openning it,it shows the message -- An error occurred reading the startup configuration file.Please contact ur administrator./.netscape/preferences.js,line 66:unterminated string literal.t,127.0.0.1 please... (3 Replies)
Discussion started by: smartgupta
3 Replies

4. Shell Programming and Scripting

Password is getting displayed

My shell script which runs on solaris has an execution in it. Contents of shell script BEGIN : Executable_filename username/password@DBinstance parameter2 parameter3 Contents of shell script END : When i launch the shell script, it connects to database to gets few details.. In the... (3 Replies)
Discussion started by: shafi2all
3 Replies

5. HP-UX

swlist is not displayed in HP-UX

Hi swlist command is not displayed in HP-UX ..it displays swlist: Command not found. uname -a HP-UX inccishh B.11.11 U 9000/800 4046719263 unlimited-user license :b: Best Regards vasanthan (4 Replies)
Discussion started by: vasanthan
4 Replies

6. UNIX for Advanced & Expert Users

script to open the specified url in a browser from a text file

Hi All, here i am struc (6 Replies)
Discussion started by: gsp
6 Replies

7. Solaris

How to open Browser

Hi, I am connecting to the remote machine via Xmanger. How can i ope browser from the termilnal. I can open gui from my terminal. (xclock works) Just wondering how to open the browser ? (2 Replies)
Discussion started by: bang_dba
2 Replies

8. Solaris

hostname not displayed

Hi, I posted a problem earlier on on how to change IP addresses on an E450. I was able to work around this and wanna say thanks to all who assisted. But now on my server, I get this error, trying to configure hosts..RPC timed out. Also, when I type on the command line, hostname, nothing is... (7 Replies)
Discussion started by: Ronny
7 Replies
Login or Register to Ask a Question