For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > February 2005 > cannot open and write file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cannot open and write file
Roll

2005-01-21, 4:00 am

i want to try writing to a file. i try this coding
<write.cgi>
#!/usr/bin/perl
open(OUTF,">>/root/a.conf");
print OUTF "anc";
close OUTF

but when i open this page using a web browser, it give me an error 403??
can anyone tell me y is this so did i miss some coding or it should be
written in another way?

Matt Garrish

2005-01-21, 4:00 am


"Roll" <lie_huo@hotmail.com> wrote in message
news:5b06d7c84f17e758419955dab21b8b78@lo
calhost.talkaboutprogramming.com...
>i want to try writing to a file. i try this coding
> <write.cgi>
> #!/usr/bin/perl
> open(OUTF,">>/root/a.conf");
> print OUTF "anc";
> close OUTF
>
> but when i open this page using a web browser, it give me an error 403??
> can anyone tell me y is this so did i miss some coding or it should be
> written in another way?
>


What does a 403 error have to do with your code?

Possible future errors include not sending a correct http header in your
script and not checking whether your open succeeded.

Matt


A. Sinan Unur

2005-01-21, 4:00 am

"Roll" <lie_huo@hotmail.com> wrote in
news:5b06d7c84f17e758419955dab21b8b78
@localhost.talkaboutprogramming.com:

> i want to try writing to a file. i try this coding
> <write.cgi>
> #!/usr/bin/perl
> open(OUTF,">>/root/a.conf");
> print OUTF "anc";
> close OUTF
>
> but when i open this page using a web browser, it give me an error
> 403?? can anyone tell me y is this so did i miss some coding or it
> should be written in another way?


The fact that you get a 403 status code means your script did not even
run (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).

Even then, your script does not seem to be a CGI script. Try the
following:

#! /usr/bin/perl

use strict;
use warnings;

use CGI;

print header,
start_html,
p('Hello World'),
end_html;

__END__

To see if you have set up your web server correctly.

I find that highly unlikely given that you seem to want to give the
whole wide world write access to root's home directory.

Note that your question at this point is not really a Perl question.
Questions that are solely about CGI your web server set up should be
directed to the relevant fora.

You may also benefit from reading:

perldoc -q 500

Sinan.
Roll

2005-01-21, 8:58 am

You may also benefit from reading:

perldoc -q 500

Sinan.

where to find this perldoc -q 500 to read??

Martin Kissner

2005-01-21, 8:58 am

Roll wrote :
>
> where to find this perldoc -q 500 to read??
>


Just type it on the command line

--
Epur Si Muove (Gallileo Gallilei)
Chris Mattern

2005-01-21, 3:58 pm

Roll wrote:

> i want to try writing to a file. i try this coding
> <write.cgi>
> #!/usr/bin/perl
> open(OUTF,">>/root/a.conf");
> print OUTF "anc";
> close OUTF
>
> but when i open this page using a web browser, it give me an error 403??
> can anyone tell me y is this so did i miss some coding or it should be
> written in another way?


You web process does not have permission to write to /root/a.conf.
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
Helgi Briem

2005-01-21, 3:58 pm

On Fri, 21 Jan 2005 08:22:40 -0500, Chris Mattern
<matternc@comcast.net> wrote:

>Roll wrote:
>
>
>You web process does not have permission to write to /root/a.conf.


..... and the OP can test this by doing things properly:

#!/usr/bin/perl
use warnings;
use strict;
my $out = '/root/a.conf';
open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
print OUTF "anc";
close OUTF or die "Cannot close $out:$!";

--
Helgi Briem hbriem AT simnet DOT is

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Tad McClellan

2005-01-21, 3:58 pm

Martin Kissner <news@chaos-net.de> wrote:
> Roll wrote :
>
> Just type it on the command line



It is asking you check for Perl Frequently Asked Questions with
the text "500" in the Question.

The "perldoc" program is installed along with the "perl" program,
so it should already be there for you to use.


But judging by what you have posted so far, you should probably
expand that to all questions that mention CGI or HTML:

perldoc -q CGI

How can I make my CGI script more efficient?

Where can I learn about CGI or Web programming in Perl?

What is the correct form of response from a CGI script?

My CGI script runs from the command line but not the browser. (500
Server Error)

How can I get better error messages from a CGI program?

How do I make sure users can't enter values into a form that cause my
CGI script to do bad things?

How do I decode a CGI form?


perldoc -q HTML

How do I remove HTML from a string?

How do I fetch an HTML file?

How do I automate an HTML form submission?


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
Roll

2005-02-28, 3:58 pm

#!/usr/bin/perl
use warnings;
use strict;
my $out = '/root/a.conf';
open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
print OUTF "anc";
close OUTF or die "Cannot close $out:$!";

can someone tell me how come after typing this code i got a 500 internal
server error ??
how do i solve this?

Paul Lalli

2005-02-28, 3:58 pm

"Roll" <lie_huo@hotmail.com> wrote in message
news:19a31f769d44ebd64678206b3ab4ebf1@lo
calhost.talkaboutprogramming.com...
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = '/root/a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
>
> can someone tell me how come after typing this code i got a 500

internal
> server error ??
> how do i solve this?


Have you read
perldoc -q 500
?

More specifically, have you actually read the entire message you
receive? The bit that tells you to check your server logs for the
error? Have you done this?

Paul Lalli


Henry Law

2005-02-28, 3:58 pm

On Mon, 28 Feb 2005 11:10:21 -0500, "Roll" <lie_huo@hotmail.com>
wrote:

>#!/usr/bin/perl
>use warnings;
>use strict;
>my $out = '/root/a.conf';
>open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
>print OUTF "anc";
>close OUTF or die "Cannot close $out:$!";
>
>can someone tell me how come after typing this code i got a 500 internal
>server error ??


This code works fine for me; it writes the line "anc" onto the end of
the file named in $out (I changed it to something that made sense on
my Windows machine).

F:\WIP>type test.pl
#!/usr/bin/perl
use warnings;
use strict;
my $out = 'F:\\WIP\\a.conf';
open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
print OUTF "anc";
close OUTF or die "Cannot close $out:$!";
F:\WIP>test.pl

F:\WIP>type a.conf
**
ancanc
F:\WIP>

I dont see the problem.
Chris Mattern

2005-02-28, 3:58 pm

Henry Law wrote:

> On Mon, 28 Feb 2005 11:10:21 -0500, "Roll" <lie_huo@hotmail.com>
> wrote:
>
>
> This code works fine for me; it writes the line "anc" onto the end of
> the file named in $out (I changed it to something that made sense on
> my Windows machine).
>
> F:\WIP>type test.pl
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $out = 'F:\\WIP\\a.conf';
> open(OUTF,">>", $out) or die "Cannot open $out for appending:$!";
> print OUTF "anc";
> close OUTF or die "Cannot close $out:$!";
> F:\WIP>test.pl
>
> F:\WIP>type a.conf
> **
> ancanc
> F:\WIP>
>
> I dont see the problem.


Henry is being a bit cruel, but his point is accurate, if you
understand it. There is nothing wrong with your Perl code;
it does what you want it to do. The problem is what you
didn't see fit to tell us, namely, that you're running
this via CGI. And your problem is with your CGI, not your
Perl.
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com