capture3(*cmd)
Class Public methods
::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 ::popen3 except opts and opts. See Process.spawn.
If opts is specified, it is sent to the command's standard input.
If opts is true, internal pipes are set to binary mode.
Example:
# dot is a command of graphviz. graph = <<'End' digraph g { a -> b } End layouted_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 thumnail image using the convert command of ImageMagick. # However, if the image stored really in a file, # system("convert", "-thumbnail", "80", "png:#{filename}", "png:-") is better # because memory consumption. # But if the image is stored in a DB or generated by gnuplot Open3.capture2 example, # Open3.capture3 is considerable. # image = File.read("/usr/share/openclipart/png/animals/mammals/sheep-md-v0.1.png", :binmode=>true) thumnail, err, s = Open3.capture3("convert -thumbnail 80 png:- png:-", :stdin_data=>image, :binmode=>true) if s.success? STDOUT.binmode; print thumnail end
Please login to continue.