rupesh has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I have a CGI Program, which gets some data from a form, and does some kind of manipulation etc.
What i want to do is list out the contents of a directory from my cgi program.
The problem is that the directory is a network path (eg. \\<computer name>\\myfolder. Using File::Find, im able to do it from a simple perl program, but it doesn't work while i put it in a cgi. Also a `dir $directory > somefile.txt ` does not produce the output to the text file.
The whole operation is done in Windows (win32).
Any help is appreciated.
Thanks

we're born with our eyes closed and our mouths wide open, and we spend our entire life trying to rectify that mistake of nature. - anonymous.

Replies are listed 'Best First'.
Re: CGI System Commands
by BrowserUk (Patriarch) on Aug 05, 2003 at 07:20 UTC

    This is almost certainly due to the account that your webserver runs as not having the permissions to access the network share that you are trying to search. A scan of the webserver log file will probably confirm this. A grep for "Access denied" might turn up the problem.

    If the webserver in question is in a secure environment (Ie. on an intranet and inaccessable to the internet), then giving the webserver account the appropriate permissions would do the trick.

    If it's accessable outside of a secure environment, then you probably want to re-think why you are trying to allow the world to see whats on the disk.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

      Thanks
      Here's what Im trying to do
      my @arr=`dir $path /b`;
      The script runs smoothly from the path c:\....apache\cgi-bin from the command prompt.
      When the script is called from a web page, it gives an error.THe cgi looks like:
      #!c:\perl\bin\perl use strict; use CGI qw(:standard); my $labelpath="\\\\<some computer name or ip address>\\<a shared folde +r (permissions - all)>"; my @arr=`dir $labelpath /b`; print header; print start_html('Thank you'); print <<EOF; <head> <title>Test</title> </head> <body text="#rrggbb" bgcolor="#D7DFEE"> </body> Hello $arr[0] <br> $arr[1]...etc. EOF print end_html;


      we're born with our eyes closed and our mouths wide open, and we spend our entire life trying to rectify that mistake of nature. - anonymous.

        When you run the script from the command line, is runs with whatever privaleges your logon id has. If you can dir the target share, then the program can.

        When the script is invoke as a cgi, it only has whatever privaleges the webserver account has. These usually defualt to very low privaleges for safety.

        Find out what account the web server runs as--ask your SysAdmin or ISP if you don't know how to find this information yourself--and then logon as that account and try your dir from the commandline. It almost certainly will give you "Access denied".

        To summarise:

        • This is nothing to do with perl.
        • Nothing to do with your code.
        • No amount of changing to your code will fix the problem.

        You need to give the webserver account the correct permissions, or talk to someone that has the authority to do this on your behalf.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.

Re: CGI System Commands
by Juerd (Abbot) on Aug 05, 2003 at 07:07 UTC

    but it doesn't work while i put it in a cgi.

    "Doesn't work" won't give you useful answers. You need to investigate what it is that it doesn't do, probably by checking returned values.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }