#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ROText; use IPC::Open3; $|++; my $mw = MainWindow->new; my $canvas = $mw->Canvas( -bg => 'white', -height =>400, -width =>500, )->pack(); my $button = $mw -> Button(-text => "Quit", -command => \&quit)->pack(-side=>'left'); my $text = $mw->ROText(-bg=>'white') ->pack( -fill => 'both', -expand => 1 ); $text->tagConfigure( 'red', -foreground => 'red' ); my $pid = open3( \*IN, \*OUT, \*ERR, "c:/gnuplot/bin/gnuplot.exe" ) || die; $mw->fileevent( \*OUT, readable => \&read_out ); $mw->fileevent( \*ERR, readable => \&read_err ); print IN "set term tkcanvas perltk interactive\n"; print IN "set output \'plot.pl\'\n"; #print IN "a=1\n"; #print IN "plot a\n"; #print IN "plot sin(x)/x\n"; #print IN "splot sin(x*y/20)\n"; print IN "plot sin(x) title 'Sine Function', tan(x) title 'Tangent'\n"; my $gnuplot = do "plot.pl"; $gnuplot->($canvas); MainLoop; sub read_out { } sub read_err { print "read_err()\n"; my $num = sysread(ERR, my $buffer, 1024 ); $text->insert( 'end', $buffer, 'red' ); } sub quit{close $pid; exit} #### open PROC, "| c:/gnuplot/bin/gnuplot.exe" || die "Could not start gnuplot: $!"; #above :the first character in the filename is a pipe symbol (|) print PROC "set xlabel 'Time'; set ylabel 'Amplitude';"; print PROC "set o 'graph.png';"; print PROC "set t png;"; print PROC "plot '-' u 1:2 t 'data' w l\n"; for( $x = 0.0; $x <= 10.0; $x += 0.1 ) { $y = exp(-$x/5)*sin( $x ); print PROC "$x $y\n"; } print PROC "e\n"; close PROC;