http://qs1969.pair.com?node_id=7248

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

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 +t.ps $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/meteo_955384773_91.ps /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 CGI.pm to handle CGI stuff. Thanks very much, -Joe