Solved

Perl cannot print contents of document to Web browser

Posted on 2007-04-08
9
230 Views
Last Modified: 2013-12-25
Perl 5 problem.  I just installed Perl 5.8.8 Build 20 on an new Windows 2003 server.  I am for some reason uanable to print the contents of a file to a web browser.  However, if I run the same script at the command line, I see all the correct output from the file there.  Why can I not get a handle on the any lines from the file and print them to the browser even using the below simple code.


#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>\n";
open(FILES, "test.dat") or warn "no file exists: $!";
$record = <FILES>;
print "$record";
print "</HTML>\n";
0
Comment
Question by:NoodlesWIU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 18872630
check your error log file of the web server, most likely your web server cannot execute the file (probably due to lack of a known interpreter)
0
 
LVL 3

Author Comment

by:NoodlesWIU
ID: 18872697
Actually I was able to partially resolve it.  For some reason I have to type in the absolute path of the file as apposed to the relative path.  ie.)  my script is in a sub folder of the root say folder 1, I should be able to use this script because the file is relative to where the script is at.

open(FILES, "test.dat") or warn "no file exists: $!";
$record = <FILES>;
print "$record";

instead I found that I have to do this...

open(FILES, "./folder1/test.dat") or warn "no file exists: $!";
$record = <FILES>;
print "$record";

Why do I have to type the absolute path instead of the relative path where the actual script file is at?  I would like to change this if possible
0
 
LVL 84

Expert Comment

by:ozo
ID: 18873321
Actually a path starting with . is a relative path.
you can
use Cwd;
print getcwd;
to show the current working directory.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 10

Expert Comment

by:xanius
ID: 18873491
Well.

acoordiung to your (partlyx successfule code),

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>\n";
open(FILES, "folder1/test.dat") or warn "no file exists: $!";
$record = <FILES>;
print "$record";
print "</HTML>\n";

would work ....
0
 
LVL 84

Expert Comment

by:ozo
ID: 18873503
the current working directory is not necessarily where the script is,
is is usually the current working directory inherited from the parent that invoked the script
0
 
LVL 84

Expert Comment

by:ozo
ID: 18873734
if you want to set the current working directory to the directory that the script is in, you might try
use File::Basename;
chdir dirname($0);
or
chdir dirname(__FILE__);
0
 
LVL 3

Author Comment

by:NoodlesWIU
ID: 18873795
Interesting.  In all of my previous experience, the working directory was always the directory where the original file was located.  Example being in HTML coding with regards to images.  if the html file was in the same directory as the image, I would always use <img src="./image_name.ext">  I am still used to Microsoft products however am delving deeper into linux using Asterisk for my PBX system, So I am still somewhat of a novice in regards to linux enviornments.

So how does the working directory change?
0
 
LVL 17

Assisted Solution

by:mjcoyne
mjcoyne earned 150 total points
ID: 18873804
The working directory of the web server (which is executing the script when it fails) is different than what you're using at the command line (where the script works).
0
 
LVL 84

Accepted Solution

by:
ozo earned 350 total points
ID: 18874063
Whoever calls the script can set the working directory that it starts with.
the current working directory has nothing to do with the base href used in img src links.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question