This is a very common "gotcha" that it would seem all Perl programmers and Perl programmer wannabes go through at some point in their Perl travels.

Stepping back from your original complaint for just a second let me share with you my typical approach for troubleshooting a CGI problem.

  1. First off understand exactly how your web server is set up. What userid is your CGI environment running as being one of the first things I want to know about. Don't assume anything, that's bad for you, stunts your growth, curls your spine and causes you to forget to use strict; in your coding. :-) A handy piece of code that I use is as follows:
    #!/usr/bin/perl -w #----------------------------------- # Script to dump my environment to a browser from CGI. # CAVEAT: Never, ever by all that is holy leave this script in a # production environment use strict; use CGI qw/ :all /; my $cgi = new CGI; print $cgi->headers,$cgi->start_html; # start the show; print hr,b("ENV Dump"); print ul( map { li($ENV{$_} } keys %ENV ); print hr,b("CGI Param Dump"); print ul( map { li($cgi->param($_)) } $cgi->param ); print $cgi->end_html; exit(0);
    This will give you an idea what you are dealing with and will be a big help in troubleshooting.
  2. Find out where your server logs are and start watching them.
  3. Embed some debugging statements into your code.
  4. Run your code and watch all the fun

Given your original complaint I'd look at system permissions for both running the command in the first place (which is why your code will behave differently at the command line than when run from CGI). Typically CGI is run as a non-elevated user and on some *nix systems it is run as "nobody" or "nofiles" which will eliminate your ability to create/modify files.

Hope this helps you along your way.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: System commands using CGI by blue_cowdawg
in thread System commands using CGI by nikhilB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.