Cgi
Hi all,
I am executing a perl CGI script(stored in a Linux machine)through my windows browser(client side ). I am not able to display terminal outputs executed through my perl CGI script. ............................................. #!/usr/bin/perl use CGI qw/:standard/; print header, start_html('First Task'); print `ls`; print end_html; ............................................. Here i want to display the output of the "ls " command on my windows browser. |
Try adding to your CGI:
Code:
use CGI::Carp qw(fatalsToBrowser); Code:
print "testing 1,2,3..."; Code:
print STDERR `ls`; --- rod. --- rod. |
Thanks for your reply.
I have modified the code as you suggested. But still the "ls" command output could not be displayed on the browser. #!/usr/bin/perl use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); header, start_html('First Task'); print "testing 1 2 3 "; print STDERR `ls`; print end_html; |
Did the ouptut from 'ls' show up in the web server's error log file? If not, then how do you know that 'ls' was actually invoked? Did you try using a fully qualified pathname for the 'ls' command? What happened there? You can verify this with something like this:
Code:
my $lsOut = `ls`; Better still, since you are using perl, try using the opendir()/readdir() functions. --- rod. |
I tried as the above, but still the "ls" output could not be displayed (on client Windows browser).
My log message is : (/etc/httpd/logs/error_log) [Wed Jun 18 12:48:26 2008] [error] [client 192.168.0.210] |
What part did you try? If you only tried the part in the [code] block, then you've merely confirmed what I've been trying to tell you since my first post. What have you done to prove that 'ls' is actually being invoked?
Get your CGI script to print the value of the PATH environment variable: Code:
print "PATH: ", $ENV{'PATH'},"\n"; Please answer all of these questions. In order to help you, you need to supply information. --- rod. |
Thanks for your help, i think the above problem will be solved if you please help me to solve the below task.
-------------------------------- #!/usr/bin/perl use CGI qw/:standard/; header, start_html('First Task'); print " I am creating a file "; print `touch xyz`; print end_html; ------------------------------------- Here, i want to create a file named "xyz" from the client(windows browser)in the server directory in which the above code runs. |
What's to solve? You haven't said what doesn't work.
Look, I like to help people solve their problems. I ask thoughtfully composed questions to try to get the information necessary to first diagnose the problem, and then to provide a solution, if one exists. Please do yourself a favor and others the courtesy of replying with at least an attempt at answering the questions that are posed. --- rod. |
Sorry for the above...
When i used the [ print "PATH: ", $ENV{'PATH'},"\n"; ] in my CGI code. I got the below output PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin The "ls" programme is in {/bin}directory. |
Okay, now we're getting somewhere. When you ran the code above, it was run as a CGI called by a web server, right? This is important, because the web server has its own user ID and attendant permissions. Running it standalone as a normal user or as root is not a valid test. If this is true, then we can be fairly sure that the ls command is actually being invoked, unless your server has restricted execution of these binaries by SElinux. I'm not sure how to selectively remove restrictions in Selinux; I normally run with is disabled. You may want to check that.
Your touch command should fail in a properly set up system, because you don't want your web server to have write permissions in the cgi-bin directory. You may be able to create files in other directories, if you give the directories appropriate permissions and ownerships. '/tmp' is often a good candidate, as it typically has world-read & world-write permissions. If you cannot write there, suspect Selinux. If you really just want to acquire directory listings, and ls is not being used merely as a trivial test, then I suggest you look at the perl functions opendir() and readdir(). These can do everything that ls can do. Code:
#! /usr/bin/perl -w --- rod. |
I got the solution. Selinux was causing this problem. I stoped the selinux and my code is now working properly.
Thanks a lot for your help. |
All times are GMT -5. The time now is 06:25 AM. |