I've made progress but I'm still having trouble getting the image to display in the browser, I'm hoping I can get input from someone.

The following code prints the A OK message and then prints
Content-type: image/png Content-type: text/html 
Software error:
Failed to open pipe: No such file or directory
#!/usr/bin/perl -w use CGI qw( :standard ); use CGI::Carp 'fatalsToBrowser'; print "Content-type: text/plain\n\n"; print p( "A OK" ); print "Content-type: image/png\n\n"; my $data = "05056670.txt"; my $plot = plotdata(); sub plotdata { open my $graph => "| gnuplot" or die "Failed to open pipe: $!\n"; my $graph; print $graph <<"gnu"; set terminal png color set output set xdata time set timefmt "%Y%m%d" set key left top title "Legend" box set grid xtics ytics set yrange [700:] set format x "%Y" set xlabel "Year" set ylabel "Sodim, water, filtered, milligrams per liter" set title "05056670 Western Stump Lake Major Ions" plot "$data" using 2:3 title "P00930 Sodium dissolved" gnu close $graph or die "Failed to close pipe: $!\n"; }
The following code appears to work at the command prompt because it prints the text and a bunch of strange characters, but it this is what the browser shows:
A OK 

Content-Type: image/png 
no image.
!/usr/bin/perl -w use CGI qw( :standard ); use CGI::Carp 'fatalsToBrowser'; my $q = new CGI; print $q->header("text/html"); print p(" A OK "); my $img = `gnuplot setcmds`; print $q->header("image/png"), $img;
setcmds file:
set terminal png color set output set xdata time set timefmt "%Y%m%d" set key left top title "Legend" box set grid xtics ytics set yrange [700:] set format x "%Y" set xlabel "Year" set ylabel "Sodim, water, filtered, milligrams per liter" set title "05056670 Western Stump Lake Major Ions" plot "05056670.txt" using 2:3 title "P00930 Sodium dissolved"
I'm sure I'm not doing something correctly, but I don't know what.

In reply to Re^2: gnuplot and CGI by kryberg
in thread gnuplot and CGI by kryberg

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.