Dear Masters,
Here is a simple executable cgi script that
simply:
- take the input text and
- print them
into a file at specific directory with a "system/exec" call,
of a perl script called prn_to_file.pl.
But why the exec/system doesn't do the job? Namely, the file is not created.
The permission in the "../results" directory also already cleared (please see below).
#!/usr/bin/perl -w
# This file name is: gettext_n_print.cgi
use CGI qw/:standard :html3/;
use CGI::Carp qw( fatalsToBrowser );
print header,
start_html('Deploying Exec/System with CGI'),
h1('Testing System/Exec function with CGI');
print_form() unless param;
print_results_to_file() if param;
print end_html;
sub print_form {
print start_multipart_form(),
strong('Your text: '),
textfield( -name => 'user_text' ), br, br
submit(-label=>'Submit'),
end_form;
}
sub print_results_to_file {
my $param1 = param('user_text');
print "This text _should_ be printed to the file : ",br,br;
print $param1,br;
# But this system/exec call doesn't do the job? Why?
system("perl prn_to_file.pl $param1 > ../results/output.txt");
# And these two also don't work
# system("echo $param1 > ../results/output.txt");
# exec("perl prn_to_file.pl $param1 > ../results/output.txt");
# In actual practice I have to make several systems call for
# a more complex perl script than just printing text like taking
# output.txt as arg of another script like this:
# system("perl other_code.pl output.txt > ../results/final.out2");
}
And
prn_to_file.pl script is just
simple like this:
#!/usr/bin/perl -w
use strict;
my $text = $ARGV[0];
print "THIS IS YOUR INPUT TEXT: $text\n";
This cgi script resides in cgi-bin. The overall permission looks like this:
under "public_html/somedir/" I have:
drwxrwxr-x 2 myname myname 4096 Jul 19 14:29 cgi-bin
drwxrwxr-x 2 myname myname 4096 Jul 19 14:29 results
and under "cgi-bin/" I have:
-rwxr-xr-x 1 myname myname 1506 Jul 19 14:29 gettext_n_print.cgi
-rwxr-xr-x 1 myname myname 292 Jul 19 13:56 prn_to_file.pl
I've supersearched the topic and also tried
to follow relevant suggestion there (like permission setting), but still I can't resolve the problem.
---
neversaint and everlastingly indebted.......
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.