how to call gnuplot from ruby?

P

Pen Ttt

i want to call gnuplot from ruby,my ruby script:
`gnuplot` <<EOF
plot sin(x)
EOF


pt@pt-laptop:~$ ruby /home/pt/r.rb ,then i get :

G N U P L O T
Version 4.2 patchlevel 6
last modified Sep 2009
System: Linux 2.6.32-22-generic

Copyright (C) 1986 - 1993, 1998, 2004, 2007 - 2009
Thomas Williams, Colin Kelley and many others

Type `help` to access the on-line reference manual.
The gnuplot FAQ is available from http://www.gnuplot.info/faq/

Send bug reports and suggestions to
<http://sourceforge.net/projects/gnuplot>


Terminal type set to 'wxt'
 
B

Benoit Daloze

i want to call gnuplot from ruby,my ruby script:
`gnuplot` <<EOF
plot sin(x)
EOF


pt@pt-laptop:~$ ruby =A0/home/pt/r.rb =A0,then i get :

=A0G N U P L O T
=A0Version 4.2 patchlevel 6
=A0last modified Sep 2009
=A0System: Linux 2.6.32-22-generic

=A0Copyright (C) 1986 - 1993, 1998, 2004, 2007 - 2009
=A0Thomas Williams, Colin Kelley and many others

=A0Type `help` to access the on-line reference manual.
=A0The gnuplot FAQ is available from http://www.gnuplot.info/faq/

=A0Send bug reports and suggestions to
<http://sourceforge.net/projects/gnuplot>


Terminal type set to 'wxt'

With popen:

IO.popen('gnuplot', 'w') { |io|
io.puts "plot sin(x)"
}

If you want easier control for reading/writing, use open3.

B.D.
 
P

Pen Ttt

IO.popen('gnuplot', 'w') { |io|
io.puts "plot sin(x)"
}
i tested ,it's ok
but i don't understand why is ('gnuplot', 'w'),why is not ('gnuplot',
'r'),
i call gunplot from ruby to get gnuplot's output ,so maybe it's
('gnuplot', 'r'),
when i use ('gnuplot', 'r'), can't get what i want,
could you tell me the reason of ('gnuplot', 'w')?
 
P

Pen Ttt

i don't know the difference of w and r.
program_a1:
f=IO.popen("gunzip -c ~/grid.zip","w")
while line=f.gets
print line
end
program_a2:
f=IO.popen("gunzip -c ~/grid.zip","r")
while line=f.gets
print line
end
program_a1 and program_a2 all can run ,what's the difference?

there is game--freeciv installed in my computer.
programb1:
File.popen("/usr/games/civ","w") do |pipe|
quote = pipe.gets
puts quote
end

programb2:
File.popen("/usr/games/civ","r") do |pipe|
quote = pipe.gets
puts quote
end
program_b1 and program_b2 all can run ,what's the difference?
 
R

Robert Dober

IO.popen('gnuplot', 'w') { |io|
=A0io.puts "plot sin(x)"
}
i tested ,it's ok
but i don't understand why is ('gnuplot', 'w'),why is not ('gnuplot',
'r'),
you are writing to the handle, right?
BTW were there not some Ruby bindings for Gnuplot, not sure though.
HTH
R.
 
J

Joel VanderWerf

Robert said:
you are writing to the handle, right?
BTW were there not some Ruby bindings for Gnuplot, not sure though.

There is a gnuplot gem which IIRC makes the gnuplot interface more
object oriented.

I wrote a library that retains the native gnuplot command interface, but
improves the experience in other ways (handling tempfiles and fixing
some problems with window persistence and zombie processes). See this
thread, for example:

http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/b69fce4b8b6b002b
 
L

Lars Haugseth

* Joel VanderWerf said:
There is a gnuplot gem which IIRC makes the gnuplot interface more
object oriented.

The latest version of the gnuplot gem is 2.3.1, but I'm unable to find
any documentation online (or even a homepage) that is even remotely up
to date.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top