method
capture3
Ruby latest stable (v2_5_5)
-
0 notes -
Class: Open3
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180 (0)
- 1_9_3_125 (-2)
- 1_9_3_392 (0)
- 2_1_10 (20)
- 2_2_9 (38)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
capture3(*cmd, stdin_data: '', binmode: false, **opts)
public
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