#!/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");
}
####
#!/usr/bin/perl -w
use strict;
my $text = $ARGV[0];
print "THIS IS YOUR INPUT TEXT: $text\n";
####
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