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

Hello all, I am trying to take an existing perl script, which works correctly, and make it accessible via our server (mac os x). The script takes user input, just a series of DNA sequences to compare, and parses the data from this pair from a master file of all pairwise comparisons. This data is then written to an output file (output.fpd). All of the above works correctly through an HTML form page and GET function in CGI. The problem I'm having is the following system command. Which reads:  system ("./gnuplot <ibd_wndo_R5_5.p"); At this point, I just want to be able to generate the plot on the server through CGI. I'll worry about how to post it later. Instead of generating the appropriate image, the browser displays gnuplot related text: %!PS-Adobe-2.0 %%Creator: gnuplot 4.2 patchlevel 4 %%CreationDate: Tue Jul 14 12:15:07 2009 %%DocumentFonts: (atend) %%BoundingBox: 50 50 554 770 %%Orientation: Landscape %%Pages: (atend) %%EndComments %%BeginProlog /gnudict 256 dict def gnudict begin % % The following 6 true/false flags may be edited by hand if required % The unit line width may also be changed % /Color true def /Blacktext false def /Solid false def /Dashlength 1 def /Landscape true def /Level1 false def /Rounded false def /TransparentPatterns false def /gnulinewidth 5.000 def /userlinewidth gnulinewidth def % /vshift -33 def /dl1 { 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if There's a ton more, but I don't know how informative it would be. Again, the script runs completely successfully as a perl script from the same folder; is there something special about the system command in CGI which causes this difference?

Replies are listed 'Best First'.
Re: CGI gnuplot via system command
by moritz (Cardinal) on Jul 14, 2009 at 20:30 UTC
    If I interpret your (not very well formattted) post correctly, the browser shows postscript source code.

    I don't think that most browsers handle that in a meaningful way, so I'd recommend switching to PNG and sending the appropriate content-type.

    Or maybe your problem is deeper, and you're trying to send image data and HTML in a single request? Without seeing more of your code that's hard to tell.

Re: CGI gnuplot via system command
by roboticus (Chancellor) on Jul 15, 2009 at 04:02 UTC
    RussCD:

    It appears that your gnuplot script doesn't set the appropriate output device and is defaulting to postscript. You'll want to specify an output that the browser can render, such as PNG, TIF, etc.

    ...roboticus