Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Using CAT command in Perl-CGI script (http://www.go4expert.com/forums/using-cat-command-perl-cgi-script-t3223/)

upgundecha 2Mar2007 14:14

Using CAT command in Perl-CGI script
 
Hi,

How I can cat a file's contents through Perl-CGI. I want to write a Perl-CGI program which will accept file's name from a browser on Windows machine and then cat the contents of that file back to browser window. Any thoughts how to do this?

Thanks in Advance,

pradeep 2Mar2007 16:56

Re: Using CAT command in Perl-CGI script
 
Here's the code

Code: Perl

#!/usr/bin/perl
 
 use CGI;
 
 my $q = new CGI;
 
 $file = $q->param('file') || $ARGV[0];
 
 if(-f $file)
 {
     $txt = qx(cat $file);
 }
 else
 {
     $txt = "File doesn't not exist!";
 }
 
 print $q->header,$txt;


upgundecha 2Mar2007 18:14

Re: Using CAT command in Perl-CGI script
 
Hey thanks Pradeep,

But How I can take file name in IE on Windows? And Do I need to give this CGI script root access?

Regards,

pradeep 2Mar2007 18:30

Re: Using CAT command in Perl-CGI script
 
Just like you do it in *nix, just that you need to have drive names in the beginning of the path/to/file.

Well you needn't give the script root access, if you are running it from a Web Server apache needs to have read permissions to the file.


All times are GMT +5.5. The time now is 18:27.