Flowdock
method

capture3

Importance_2
Ruby latest stable (v2_5_5) - 0 notes - Class: Open3
capture3(*cmd, stdin_data: '', binmode: false, **opts) private

Open3.capture3 captures the standard output and the standard error of a command.

stdout_str, stderr_str, status = Open3.capture3([env,] cmd... [, opts])

The arguments env, cmd and opts are passed to Open3.popen3 except opts[:stdin_data] and opts[:binmode]. See Process.spawn.

If opts[:stdin_data] is specified, it is sent to the command’s standard input.

If opts[:binmode] is true, internal pipes are set to binary mode.

Examples:

# dot is a command of graphviz.
graph = <<'End'
  digraph g {
    a -> b
  }
End
drawn_graph, dot_log = Open3.capture3("dot -v", :stdin_data=>graph)

o, e, s = Open3.capture3("echo abc; sort >&2", :stdin_data=>"foo\nbar\nbaz\n")
p o #=> "abc\n"
p e #=> "bar\nbaz\nfoo\n"
p s #=> #<Process::Status: pid 32682 exit 0>

# generate a thumbnail image using the convert command of ImageMagick.
# However, if the image is really stored in a file,
# system("convert", "-thumbnail", "80", "png:#{filename}", "png:-") is better
# because of reduced memory consumption.
# But if the image is stored in a DB or generated by the gnuplot Open3.capture2 example,
# Open3.capture3 should be considered.
#
image = File.read("/usr/share/openclipart/png/animals/mammals/sheep-md-v0.1.png", :binmode=>true)
thumbnail, err, s = Open3.capture3("convert -thumbnail 80 png:- png:-", :stdin_data=>image, :binmode=>true)
if s.success?
  STDOUT.binmode; print thumbnail
end
Show source
Register or log in to add new notes.