Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is one of those "it shouldn't do that" kind of things. I've got a script that works fine when run as user www from a shell prompt, but fails when called via CGI (which also runs as www). Instead of generating a GIF file, the system command just returns an empty string and does nothing. It does not appear to be a problem with: the command itself, string interpolation, failure to execute the command, or user permissions. My best theory is, when running as a CGI, there is a subtle change between the string I put in backticks, and the command that actually gets passed to the system, probably related to argument parsing. But I can't pin down exactly what's happening. Evidence in support of this: 1) The script works perfectly from a shell prompt (both C and bourne), under the same user id as the web server uses. 2) Earlier backtick statements work just fine, under both shell and CGI. 3) When I remove all the arguments from the command I'm passing, I get the "help screen" output, as expected. 4) If I copy the string that is put in backquotes, and paste it into a shell window, it runs just fine. 5) I've tried using the system() command in place of backticks, both passing the entire string in and separating out the individual arguments as separate strings, with no change. This is the snippet that is behaving so strangely.
srand (time ^ $$ ^ unpack "%32L*", `ps axww | gzip`); my $image_output = "/tmp/grads_www/" . $function_name . "_" . time + . "_" . int(rand 1000); my $convert_to_gif_string = "/usr/homes/joew/ImageMagick-5.1.1/convert -rotate 90 $image_outpu $image_output.gif"; $output .= "SHELL >> $convert_to_gif_string\n"; $output .= `$convert_to_gif_string`; if (open IMAGE_FILE, $image_output . ".gif") { print $query->header('image/gif'); while (<IMAGE_FILE>) { print; } } else { print $query->header('text/plain'); print $output; print "\nfailed on open: $image_output.gif\n"; }
Output when run from shell is the contents of the GIF file. Output when run as CGI is: SHELL >> /usr/homes/joew/ImageMagick-5.1.1/convert -rotate 90 /tmp/grads_www/ /tmp/grads_www/meteo_955384773_91.gif failed on open: /tmp/grads_www/meteo_955384773_91.gif Anyone know what is going on? Or even any ideas on a work-around, or further tests to run? I'm completely stumped. FYI, if you can't tell, I'm using to handle CGI stuff. Thanks very much, -Joe

In reply to mysterious backticks/system() behavior in CGI script by jwielgos

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2022-07-02 21:07 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (103 votes). Check out past polls.