class NumPlot::Process

The class communicating a gnuplot subprocess.

In many cases, you use {Plotter#plot} and you don’t need to use this class directly.

Attributes

output[R]

Output string from a gnuplot subprocess. @return [String, nil]

Public Class Methods

command(name, persist) click to toggle source

Return a command line string to invoke a subprocess. @!visibility private

# File lib/numplot.rb, line 224
def self.command(name, persist)
  name += " -persist" if persist
  name
end
new(pipe, wait) click to toggle source

Create a Process object for already opened pipe. Normally, you had better to use {.open} to create a new object. @param pipe a pipe to communicate to a subprocess @param wait wait for the output from a subprocess

# File lib/numplot.rb, line 162
def initialize(pipe, wait)
  @pipe = pipe
  @wait = wait
  @output = nil
end
open(persist=true, waiting=true, name="gnuplot") { |pr| ... } click to toggle source

Open a gnuplot process.

If a block is given, the block is invoked with the opened Process object. Otherwise, opened Process object is returned. If you give true as persist, -persist option is added to the command line of gnuplot. @param persist add -persist option to gnuplot as a command line option @param waiting wait for termination of stdout of gnuplot pipe @param name the name of the gnuplot executable file

# File lib/numplot.rb, line 207
def self.open(persist=true, waiting=true, name="gnuplot")
  pr = new(IO.popen(command(name, persist), "w+"), waiting)
  
  if block_given?
    begin
      yield pr
    ensure
      pr.close
    end
    return pr.output
  else
    return pr
  end
end

Public Instance Methods

close() click to toggle source

Close the pipe and terminate the subprocess.

If you specify wait=true when the object is constructed, @return [void]

# File lib/numplot.rb, line 176
def close
  if @wait
    @pipe.close_write
    @output = @pipe.read
    @pipe.close
  else
    @pipe.close
  end
end
puts(str) click to toggle source

Write str and a newline to the subprocess @return [void]

# File lib/numplot.rb, line 194
def puts(str)
  @pipe.puts(str)
end
write(str) click to toggle source

Write str to the subprocess. @return [void]

# File lib/numplot.rb, line 188
def write(str)
  @pipe.write(str)
end