Solved

Perl cannot print contents of document to Web browser

Posted on 2007-04-08
9
229 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
troubleshoot a python script 8 117
IDE for Python 5 109
Remote Exchange powershell returns different results 13 70
Merging two files with Perl 5 60
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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.…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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