How to call gnuplot from ruby?

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'

···

--
Posted via http://www.ruby-forum.com/.

With popen:

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

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

B.D.

···

On 27 May 2010 13:07, Pen Ttt <myocean135@yahoo.cn> wrote:

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 gnuplot FAQ

Send bug reports and suggestions to
<http://sourceforge.net/projects/gnuplot&gt;

Terminal type set to 'wxt'
--
Posted via http://www.ruby-forum.com/\.

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')?

···

--
Posted via http://www.ruby-forum.com/.

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?

···

--
Posted via http://www.ruby-forum.com/.

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

···

On Fri, May 28, 2010 at 2:51 AM, Pen Ttt <myocean135@yahoo.cn> wrote:

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'),

Robert Dober wrote:

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'),

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

···

On Fri, May 28, 2010 at 2:51 AM, Pen Ttt <myocean135@yahoo.cn> wrote:

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.

···

* Joel VanderWerf <joelvanderwerf@gmail.com> wrote:

Robert Dober wrote:

On Fri, May 28, 2010 at 2:51 AM, Pen Ttt <myocean135@yahoo.cn> wrote:

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'),

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.

--
Lars Haugseth

Lars Haugseth wrote:

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.

http://rgplot.rubyforge.org/

It look a little out of date, but maybe it helps?