Solved

Can't run a script called from a HTML Page but can from the Command Line

Posted on 2003-11-05
6
176 Views
Last Modified: 2010-03-04
I have a simple script that opens a file and concatenates a line of text to the end of the file before closing it again. The script works fine when used from the command line on my PC. But when I call the file form an HTML Page the script dosn't work - nothing gets written to the file.

HTML Code (addNewsItem.html):
================================================
<FORM ACTION="scripts/addNewsItem.pl" METHOD="POST">
.
.
.
</FORM>


Perl Code (addNeswItem.pl):
================================================
#!/usr/bin/perl -w
use CGI::Carp "fatalsToBrowser";

$string="Today there was a car crash on the I5";

$outputFile="newsHeading.js";
open(OUTPUT,">>$outputFile") || die("Cannot Open File");
print OUTPUT "$string";            
close(OUTPUT);


There is more in both files but I guess this is the bones of the source....

Any help,
- Troy
0
Comment
Question by:Troyh
6 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 25 total points
ID: 9691664
A script run from the command line runs with your permissions.

A script run under the web server typically runs with the permissions of the user 'nobody'. On most systems, 'nobody' does not have permission to create files or write on files just anywhere.

Your script appears to be properly written to send notice of this error back to you. Does it? Or does it fail to complain, too?
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9691668
Is newsHeading.js is same path with your perl script?

~ fantasy ~
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 25 total points
ID: 9691773
Never use relative paths in CGI scripts.  You can *never* guarantee your current working directory.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9696974
why not simply check the server logs, error log in particular?
think that Tintin is very close to the first mistake ..
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10049577
Nothing has happened on this question in more than 8 weeks. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between jmcg and Tintin.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now