Solved

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

Posted on 2003-11-05
6
185 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now