ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- PKt]è¨Á÷77 popen2e-i.rinu„[µü¤U:RDoc::AnyMethod[iI" popen2e:EFI"Open3#popen2e;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"DOpen3.popen2e is similar to Open3.popen3 except that it merges ;TI">the standard output stream and the standard error stream.;To:RDoc::Markup::BlankLineo; ; [I"Block form:;T@o:RDoc::Markup::Verbatim; [ I"QOpen3.popen2e([env,] cmd... [, opts]) {|stdin, stdout_and_stderr, wait_thr| ;TI"8 pid = wait_thr.pid # pid of the started process. ;TI" ... ;TI"G exit_status = wait_thr.value # Process::Status object returned. ;TI"} ;T: @format0o; ; [I"Non-block form:;T@o; ; [ I"Pstdin, stdout_and_stderr, wait_thr = Open3.popen2e([env,] cmd... [, opts]) ;TI" ... ;TI"Zstdin.close # stdin and stdout_and_stderr should be closed explicitly in this form. ;TI"stdout_and_stderr.close ;T; 0o; ; [I"HSee Process.spawn for the optional hash arguments _env_ and _opts_.;T@o; ; [I" Example:;To; ; [I"# check gcc warnings ;TI"source = "foo.c" ;TI"5Open3.popen2e("gcc", "-Wall", source) {|i,oe,t| ;TI" oe.each {|line| ;TI" if /warning/ =~ line ;TI" ... ;TI" end ;TI" } ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmd, **opts, &block);T@4FI" Open3;FcRDoc::NormalModule00PKt]À² ½½ pipeline-i.rinu„[µü¤U:RDoc::AnyMethod[iI" pipeline:EFI"Open3#pipeline;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"=Open3.pipeline starts a list of commands as a pipeline. ;TI"2It waits for the completion of the commands. ;TI"=No pipes are created for stdin of the first command and ;TI" stdout of the last command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I" [#, ;TI"0# #, ;TI"0# #] ;TI" ;TI"+fname = "/usr/share/man/man1/ls.1.gz" ;TI"=Open3.pipeline(["zcat", fname], "nroff -man", "colcrt") ;TI" ;TI"6# convert PDF to PS and send to a printer by lpr ;TI"pdf_file = "paper.pdf" ;TI"printer = "printer-name" ;TI"0Open3.pipeline(["pdftops", pdf_file, "-"], ;TI"- ["lpr", "-P#{printer}"]) ;TI" ;TI"# count lines ;TI"HOpen3.pipeline("sort", "uniq -c", :in=>"names.txt", :out=>"count") ;TI" ;TI"# cyclic pipeline ;TI"r,w = IO.pipe ;TI"w.print "ibase=14\n10\n" ;TI";Open3.pipeline("bc", "tee /dev/tty", :in=>r, :out=>w) ;TI" #=> 14 ;TI" # 18 ;TI" # 22 ;TI" # 30 ;TI" # 42 ;TI" # 58 ;TI" # 78 ;TI" # 106 ;TI" # 202;T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts);T@FFI" Open3;FcRDoc::NormalModule00PKt]OüÊÊcapture2e-i.rinu„[µü¤U:RDoc::AnyMethod[iI"capture2e:EFI"Open3#capture2e;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"VOpen3.capture2e captures the standard output and the standard error of a command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Mstdout_and_stderr_str, status = Open3.capture2e([env,] cmd... [, opts]) ;T: @format0o; ; [I"GThe arguments env, cmd and opts are passed to Open3.popen3 except ;TI">opts[:stdin_data] and opts[:binmode]. See Process.spawn.;T@o; ; [I"SIf opts[:stdin_data] is specified, it is sent to the command's standard input.;T@o; ; [I"FIf opts[:binmode] is true, internal pipes are set to binary mode.;T@o; ; [I" Example:;T@o; ; [I"# capture make log ;TI"*make_log, s = Open3.capture2e("make");T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"3(*cmd, stdin_data: '', binmode: false, **opts);T@#FI" Open3;FcRDoc::NormalModule00PKt]ÄæN²ãã capture3-c.rinu„[µü¤U:RDoc::AnyMethod[iI" capture3:EFI"Open3::capture3;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"UOpen3.capture3 captures the standard output and the standard error of a command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Mstdout_str, stderr_str, status = Open3.capture3([env,] cmd... [, opts]) ;T: @format0o; ; [I"GThe arguments env, cmd and opts are passed to Open3.popen3 except ;TI">opts[:stdin_data] and opts[:binmode]. See Process.spawn.;T@o; ; [I"SIf opts[:stdin_data] is specified, it is sent to the command's standard input.;T@o; ; [I"FIf opts[:binmode] is true, internal pipes are set to binary mode.;T@o; ; [I"Examples:;T@o; ; [I"%# dot is a command of graphviz. ;TI"graph = <<'End' ;TI" digraph g { ;TI" a -> b ;TI" } ;TI" End ;TI"Idrawn_graph, dot_log = Open3.capture3("dot -v", :stdin_data=>graph) ;TI" ;TI"To, e, s = Open3.capture3("echo abc; sort >&2", :stdin_data=>"foo\nbar\nbaz\n") ;TI"p o #=> "abc\n" ;TI"p e #=> "bar\nbaz\nfoo\n" ;TI"2p s #=> # ;TI" ;TI"L# generate a thumbnail image using the convert command of ImageMagick. ;TI"9# However, if the image is really stored in a file, ;TI"S# system("convert", "-thumbnail", "80", "png:#{filename}", "png:-") is better ;TI".# because of reduced memory consumption. ;TI"^# But if the image is stored in a DB or generated by the gnuplot Open3.capture2 example, ;TI",# Open3.capture3 should be considered. ;TI"# ;TI"gimage = File.read("/usr/share/openclipart/png/animals/mammals/sheep-md-v0.1.png", :binmode=>true) ;TI"qthumbnail, err, s = Open3.capture3("convert -thumbnail 80 png:- png:-", :stdin_data=>image, :binmode=>true) ;TI"if s.success? ;TI"' STDOUT.binmode; print thumbnail ;TI"end;T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"3(*cmd, stdin_data: '', binmode: false, **opts);T@:FI" Open3;FcRDoc::NormalModule00PKt]dí[Þ??pipeline_rw-i.rinu„[µü¤U:RDoc::AnyMethod[iI"pipeline_rw:EFI"Open3#pipeline_rw;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JOpen3.pipeline_rw starts a list of commands as a pipeline with pipes ;TI"Pwhich connect to stdin of the first command and stdout of the last command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"[Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads| ;TI" ... ;TI"} ;TI" ;TI"Zfirst_stdin, last_stdout, wait_threads = Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) ;TI" ... ;TI"first_stdin.close ;TI"last_stdout.close ;T: @format0o; ; [I"'Each cmd is a string or an array. ;TI"AIf it is an array, the elements are passed to Process.spawn.;T@o; ; [ I" cmd: ;TI"_ commandline command line string which is passed to a shell ;TI"_ [env, commandline, opts] command line string which is passed to a shell ;TI"b [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) ;TI"h [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) ;TI" ;TI"@Note that env and opts are optional, as for Process.spawn. ;T; 0o; ; [I"EThe options to pass to Process.spawn are constructed by merging ;TI"5+opts+, the last hash element of the array, and ;TI"?specifications for the pipes between each of the commands.;T@o; ; [I" Example:;T@o; ; [I"=Open3.pipeline_rw("tr -dc A-Za-z", "wc -c") {|i, o, ts| ;TI"F i.puts "All persons more than a mile high to leave the court." ;TI" i.close ;TI" p o.gets #=> "42\n" ;TI"} ;TI" ;TI"EOpen3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs| ;TI" stdin.puts "foo" ;TI" stdin.puts "bar" ;TI" stdin.puts "baz" ;TI"+ stdin.close # send EOF to sort. ;TI"E p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n" ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@>FI" Open3;FcRDoc::NormalModule00PKt]çøð"ÀÀcdesc-Open3.rinu„[µü¤U:RDoc::NormalModule[iI" Open3:EF@0o:RDoc::Markup::Document: @parts[o;;[o:RDoc::Markup::Paragraph;[ I"SOpen3 grants you access to stdin, stdout, stderr and a thread to wait for the ;TI"1child process when running another program. ;TI"SYou can specify various attributes, redirections, current directory, etc., of ;TI"6the program in the same way as for Process.spawn.;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0;[o; ;[I"3Open3.popen3 : pipes for stdin, stdout, stderr;To;;0;[o; ;[I"+Open3.popen2 : pipes for stdin, stdout;To;;0;[o; ;[I">Open3.popen2e : pipes for stdin, merged stdout and stderr;To;;0;[o; ;[I"MOpen3.capture3 : give a string for stdin; get strings for stdout, stderr;To;;0;[o; ;[I"FOpen3.capture2 : give a string for stdin; get a string for stdout;To;;0;[o; ;[I"YOpen3.capture2e : give a string for stdin; get a string for merged stdout and stderr;To;;0;[o; ;[I"LOpen3.pipeline_rw : pipes for first stdin and last stdout of a pipeline;To;;0;[o; ;[I":Open3.pipeline_r : pipe for last stdout of a pipeline;To;;0;[o; ;[I":Open3.pipeline_w : pipe for first stdin of a pipeline;To;;0;[o; ;[I":Open3.pipeline_start : run a pipeline without waiting;To;;0;[o; ;[I"@Open3.pipeline : run a pipeline and wait for its completion;T: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[[[[I" class;T[[: public[[I" capture2;FI"lib/open3.rb;T[I"capture2e;F@X[I" capture3;F@X[I" pipeline;F@X[I"pipeline_r;F@X[I"pipeline_rw;F@X[I"pipeline_start;F@X[I"pipeline_w;F@X[I" popen2;F@X[I" popen2e;F@X[I" popen3;F@X[:protected[[: private[[I" instance;T[[;[[;[[;[[@W@X[@Z@X[@\@X[@^@X[@`@X[@b@X[@d@X[@f@X[@h@X[@j@X[@l@X[[U:RDoc::Context::Section[i0o;;[;0;0[@L@LcRDoc::TopLevelPKt]}i 477 popen2e-c.rinu„[µü¤U:RDoc::AnyMethod[iI" popen2e:EFI"Open3::popen2e;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"DOpen3.popen2e is similar to Open3.popen3 except that it merges ;TI">the standard output stream and the standard error stream.;To:RDoc::Markup::BlankLineo; ; [I"Block form:;T@o:RDoc::Markup::Verbatim; [ I"QOpen3.popen2e([env,] cmd... [, opts]) {|stdin, stdout_and_stderr, wait_thr| ;TI"8 pid = wait_thr.pid # pid of the started process. ;TI" ... ;TI"G exit_status = wait_thr.value # Process::Status object returned. ;TI"} ;T: @format0o; ; [I"Non-block form:;T@o; ; [ I"Pstdin, stdout_and_stderr, wait_thr = Open3.popen2e([env,] cmd... [, opts]) ;TI" ... ;TI"Zstdin.close # stdin and stdout_and_stderr should be closed explicitly in this form. ;TI"stdout_and_stderr.close ;T; 0o; ; [I"HSee Process.spawn for the optional hash arguments _env_ and _opts_.;T@o; ; [I" Example:;To; ; [I"# check gcc warnings ;TI"source = "foo.c" ;TI"5Open3.popen2e("gcc", "-Wall", source) {|i,oe,t| ;TI" oe.each {|line| ;TI" if /warning/ =~ line ;TI" ... ;TI" end ;TI" } ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmd, **opts, &block);T@4FI" Open3;FcRDoc::NormalModule00PKt]Ú»¦Z8 8 popen3-i.rinu„[µü¤U:RDoc::AnyMethod[iI" popen3:EFI"Open3#popen3;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"KOpen stdin, stdout, and stderr streams and start external executable. ;TI"GIn addition, a thread to wait for the started process is created. ;TI"PThe thread has a pid method and a thread variable :pid which is the pid of ;TI"the started process.;To:RDoc::Markup::BlankLineo; ; [I"Block form:;T@o:RDoc::Markup::Verbatim; [ I"MOpen3.popen3([env,] cmd... [, opts]) {|stdin, stdout, stderr, wait_thr| ;TI"8 pid = wait_thr.pid # pid of the started process. ;TI" ... ;TI"G exit_status = wait_thr.value # Process::Status object returned. ;TI"} ;T: @format0o; ; [I"Non-block form:;T@o; ; [ I"Lstdin, stdout, stderr, wait_thr = Open3.popen3([env,] cmd... [, opts]) ;TI"8pid = wait_thr[:pid] # pid of the started process ;TI" ... ;TI"Wstdin.close # stdin, stdout and stderr should be closed explicitly in this form. ;TI"stdout.close ;TI"stderr.close ;TI"Fexit_status = wait_thr.value # Process::Status object returned. ;T; 0o; ; [I"DThe parameters env, cmd, and opts are passed to Process.spawn. ;TI"TA commandline string and a list of argument strings can be accepted as follows:;T@o; ; [I"2Open3.popen3("echo abc") {|i, o, e, t| ... } ;TI"5Open3.popen3("echo", "abc") {|i, o, e, t| ... } ;TI"@Open3.popen3(["echo", "argv0"], "abc") {|i, o, e, t| ... } ;T; 0o; ; [I"]If the last parameter, opts, is a Hash, it is recognized as an option for Process.spawn.;T@o; ; [I"1Open3.popen3("pwd", :chdir=>"/") {|i,o,e,t| ;TI" p o.read.chomp #=> "/" ;TI"} ;T; 0o; ; [I">wait_thr.value waits for the termination of the process. ;TI"?The block form also waits for the process when it returns.;T@o; ; [I"PClosing stdin, stdout and stderr does not wait for the process to complete.;T@o; ; [ I"/You should be careful to avoid deadlocks. ;TI"+Since pipes are fixed length buffers, ;TI">Open3.popen3("prog") {|i, o, e, t| o.read } deadlocks if ;TI"6the program generates too much output on stderr. ;TI"TYou should read stdout and stderr simultaneously (using threads or IO.select). ;TI"IHowever, if you don't need stderr output, you can use Open3.popen2. ;TI"UIf merged stdout and stderr output is not a problem, you can use Open3.popen2e. ;TI"fIf you really need stdout and stderr output as separate strings, you can consider Open3.capture3.;T: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmd, **opts, &block);T@JFI" Open3;FcRDoc::NormalModule00PKt]Bzeݯ¯pipeline_w-i.rinu„[µü¤U:RDoc::AnyMethod[iI"pipeline_w:EFI"Open3#pipeline_w;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JOpen3.pipeline_w starts a list of commands as a pipeline with a pipe ;TI"2which connects to stdin of the first command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"MOpen3.pipeline_w(cmd1, cmd2, ... [, opts]) {|first_stdin, wait_threads| ;TI" ... ;TI"} ;TI" ;TI"Lfirst_stdin, wait_threads = Open3.pipeline_w(cmd1, cmd2, ... [, opts]) ;TI" ... ;TI"first_stdin.close ;T: @format0o; ; [I"'Each cmd is a string or an array. ;TI"AIf it is an array, the elements are passed to Process.spawn.;T@o; ; [ I" cmd: ;TI"_ commandline command line string which is passed to a shell ;TI"_ [env, commandline, opts] command line string which is passed to a shell ;TI"b [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) ;TI"h [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) ;TI" ;TI"@Note that env and opts are optional, as for Process.spawn. ;T; 0o; ; [I" Example:;T@o; ; [I"COpen3.pipeline_w("bzip2 -c", :out=>"/tmp/hello.bz2") {|i, ts| ;TI" i.puts "hello" ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@.FI" Open3;FcRDoc::NormalModule00PKt]cÀ ,, capture2-c.rinu„[µü¤U:RDoc::AnyMethod[iI" capture2:EFI"Open3::capture2;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I">Open3.capture2 captures the standard output of a command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Astdout_str, status = Open3.capture2([env,] cmd... [, opts]) ;T: @format0o; ; [I"GThe arguments env, cmd and opts are passed to Open3.popen3 except ;TI">opts[:stdin_data] and opts[:binmode]. See Process.spawn.;T@o; ; [I"SIf opts[:stdin_data] is specified, it is sent to the command's standard input.;T@o; ; [I"FIf opts[:binmode] is true, internal pipes are set to binary mode.;T@o; ; [I" Example:;T@o; ; [I"6# factor is a command for integer factorization. ;TI"8o, s = Open3.capture2("factor", :stdin_data=>"42") ;TI"p o #=> "42: 2 3 7\n" ;TI" ;TI"1# generate x**2 graph in png using gnuplot. ;TI" gnuplot_commands = <<"End" ;TI" set terminal png ;TI"! plot x**2, "-" with lines ;TI" 1 14 ;TI" 2 1 ;TI" 3 8 ;TI" 4 5 ;TI" e ;TI" End ;TI"Ximage, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true);T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"3(*cmd, stdin_data: '', binmode: false, **opts);T@0FI" Open3;FcRDoc::NormalModule00PKt]¦Áå>ôôpipeline_start-i.rinu„[µü¤U:RDoc::AnyMethod[iI"pipeline_start:EFI"Open3#pipeline_start;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"COpen3.pipeline_start starts a list of commands as a pipeline. ;TI"=No pipes are created for stdin of the first command and ;TI" stdout of the last command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"DOpen3.pipeline_start(cmd1, cmd2, ... [, opts]) {|wait_threads| ;TI" ... ;TI"} ;TI" ;TI"Cwait_threads = Open3.pipeline_start(cmd1, cmd2, ... [, opts]) ;TI" ... ;T: @format0o; ; [I"'Each cmd is a string or an array. ;TI"AIf it is an array, the elements are passed to Process.spawn.;T@o; ; [ I" cmd: ;TI"_ commandline command line string which is passed to a shell ;TI"_ [env, commandline, opts] command line string which is passed to a shell ;TI"b [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) ;TI"h [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) ;TI" ;TI"@Note that env and opts are optional, as for Process.spawn. ;T; 0o; ; [I" Example:;T@o; ; [I" # Run xeyes in 10 seconds. ;TI")Open3.pipeline_start("xeyes") {|ts| ;TI" sleep 10 ;TI" t = ts[0] ;TI"# Process.kill("TERM", t.pid) ;TI"E p t.value #=> # ;TI"} ;TI" ;TI"3# Convert pdf to ps and send it to a printer. ;TI"1# Collect error message of pdftops and lpr. ;TI"pdf_file = "paper.pdf" ;TI"printer = "printer-name" ;TI"err_r, err_w = IO.pipe ;TI"6Open3.pipeline_start(["pdftops", pdf_file, "-"], ;TI"3 ["lpr", "-P#{printer}"], ;TI"- :err=>err_w) {|ts| ;TI" err_w.close ;TI"9 p err_r.read # error messages of pdftops and lpr. ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@>FI" Open3;FcRDoc::NormalModule00PKt]!ð£ï½½ pipeline-c.rinu„[µü¤U:RDoc::AnyMethod[iI" pipeline:EFI"Open3::pipeline;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"=Open3.pipeline starts a list of commands as a pipeline. ;TI"2It waits for the completion of the commands. ;TI"=No pipes are created for stdin of the first command and ;TI" stdout of the last command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I" [#, ;TI"0# #, ;TI"0# #] ;TI" ;TI"+fname = "/usr/share/man/man1/ls.1.gz" ;TI"=Open3.pipeline(["zcat", fname], "nroff -man", "colcrt") ;TI" ;TI"6# convert PDF to PS and send to a printer by lpr ;TI"pdf_file = "paper.pdf" ;TI"printer = "printer-name" ;TI"0Open3.pipeline(["pdftops", pdf_file, "-"], ;TI"- ["lpr", "-P#{printer}"]) ;TI" ;TI"# count lines ;TI"HOpen3.pipeline("sort", "uniq -c", :in=>"names.txt", :out=>"count") ;TI" ;TI"# cyclic pipeline ;TI"r,w = IO.pipe ;TI"w.print "ibase=14\n10\n" ;TI";Open3.pipeline("bc", "tee /dev/tty", :in=>r, :out=>w) ;TI" #=> 14 ;TI" # 18 ;TI" # 22 ;TI" # 30 ;TI" # 42 ;TI" # 58 ;TI" # 78 ;TI" # 106 ;TI" # 202;T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts);T@FFI" Open3;FcRDoc::NormalModule00PKt]|HM޼¼ popen2-i.rinu„[µü¤U:RDoc::AnyMethod[iI" popen2:EFI"Open3#popen2;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"VOpen3.popen2 is similar to Open3.popen3 except that it doesn't create a pipe for ;TI"the standard error stream.;To:RDoc::Markup::BlankLineo; ; [I"Block form:;T@o:RDoc::Markup::Verbatim; [ I"EOpen3.popen2([env,] cmd... [, opts]) {|stdin, stdout, wait_thr| ;TI"8 pid = wait_thr.pid # pid of the started process. ;TI" ... ;TI"G exit_status = wait_thr.value # Process::Status object returned. ;TI"} ;T: @format0o; ; [I"Non-block form:;T@o; ; [ I"Dstdin, stdout, wait_thr = Open3.popen2([env,] cmd... [, opts]) ;TI" ... ;TI"Ostdin.close # stdin and stdout should be closed explicitly in this form. ;TI"stdout.close ;T; 0o; ; [I"HSee Process.spawn for the optional hash arguments _env_ and _opts_.;T@o; ; [I" Example:;T@o; ; [I"$Open3.popen2("wc -c") {|i,o,t| ;TI"< i.print "answer to life the universe and everything" ;TI" i.close ;TI" p o.gets #=> "42\n" ;TI"} ;TI" ;TI"$Open3.popen2("bc -q") {|i,o,t| ;TI" i.puts "obase=13" ;TI" i.puts "6 * 9" ;TI" p o.gets #=> "42\n" ;TI"} ;TI" ;TI"!Open3.popen2("dc") {|i,o,t| ;TI" i.print "42P" ;TI" i.close ;TI" p o.read #=> "*" ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmd, **opts, &block);T@"C"}, "grep", "GET /favicon.ico"], ;TI"- "logresolve") {|o, ts| ;TI" o.each_line {|line| ;TI" ... ;TI" } ;TI"} ;TI" ;TI"2Open3.pipeline_r("yes", "head -10") {|o, ts| ;TI": p o.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n" ;TI"K p ts[0].value #=> # ;TI"> p ts[1].value #=> # ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@8FI" Open3;FcRDoc::NormalModule00PKt]a Iãã capture3-i.rinu„[µü¤U:RDoc::AnyMethod[iI" capture3:EFI"Open3#capture3;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"UOpen3.capture3 captures the standard output and the standard error of a command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Mstdout_str, stderr_str, status = Open3.capture3([env,] cmd... [, opts]) ;T: @format0o; ; [I"GThe arguments env, cmd and opts are passed to Open3.popen3 except ;TI">opts[:stdin_data] and opts[:binmode]. See Process.spawn.;T@o; ; [I"SIf opts[:stdin_data] is specified, it is sent to the command's standard input.;T@o; ; [I"FIf opts[:binmode] is true, internal pipes are set to binary mode.;T@o; ; [I"Examples:;T@o; ; [I"%# dot is a command of graphviz. ;TI"graph = <<'End' ;TI" digraph g { ;TI" a -> b ;TI" } ;TI" End ;TI"Idrawn_graph, dot_log = Open3.capture3("dot -v", :stdin_data=>graph) ;TI" ;TI"To, e, s = Open3.capture3("echo abc; sort >&2", :stdin_data=>"foo\nbar\nbaz\n") ;TI"p o #=> "abc\n" ;TI"p e #=> "bar\nbaz\nfoo\n" ;TI"2p s #=> # ;TI" ;TI"L# generate a thumbnail image using the convert command of ImageMagick. ;TI"9# However, if the image is really stored in a file, ;TI"S# system("convert", "-thumbnail", "80", "png:#{filename}", "png:-") is better ;TI".# because of reduced memory consumption. ;TI"^# But if the image is stored in a DB or generated by the gnuplot Open3.capture2 example, ;TI",# Open3.capture3 should be considered. ;TI"# ;TI"gimage = File.read("/usr/share/openclipart/png/animals/mammals/sheep-md-v0.1.png", :binmode=>true) ;TI"qthumbnail, err, s = Open3.capture3("convert -thumbnail 80 png:- png:-", :stdin_data=>image, :binmode=>true) ;TI"if s.success? ;TI"' STDOUT.binmode; print thumbnail ;TI"end;T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"3(*cmd, stdin_data: '', binmode: false, **opts);T@:FI" Open3;FcRDoc::NormalModule00PKt];F)ž¼¼ popen2-c.rinu„[µü¤U:RDoc::AnyMethod[iI" popen2:EFI"Open3::popen2;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"VOpen3.popen2 is similar to Open3.popen3 except that it doesn't create a pipe for ;TI"the standard error stream.;To:RDoc::Markup::BlankLineo; ; [I"Block form:;T@o:RDoc::Markup::Verbatim; [ I"EOpen3.popen2([env,] cmd... [, opts]) {|stdin, stdout, wait_thr| ;TI"8 pid = wait_thr.pid # pid of the started process. ;TI" ... ;TI"G exit_status = wait_thr.value # Process::Status object returned. ;TI"} ;T: @format0o; ; [I"Non-block form:;T@o; ; [ I"Dstdin, stdout, wait_thr = Open3.popen2([env,] cmd... [, opts]) ;TI" ... ;TI"Ostdin.close # stdin and stdout should be closed explicitly in this form. ;TI"stdout.close ;T; 0o; ; [I"HSee Process.spawn for the optional hash arguments _env_ and _opts_.;T@o; ; [I" Example:;T@o; ; [I"$Open3.popen2("wc -c") {|i,o,t| ;TI"< i.print "answer to life the universe and everything" ;TI" i.close ;TI" p o.gets #=> "42\n" ;TI"} ;TI" ;TI"$Open3.popen2("bc -q") {|i,o,t| ;TI" i.puts "obase=13" ;TI" i.puts "6 * 9" ;TI" p o.gets #=> "42\n" ;TI"} ;TI" ;TI"!Open3.popen2("dc") {|i,o,t| ;TI" i.print "42P" ;TI" i.close ;TI" p o.read #=> "*" ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmd, **opts, &block);T@ # ;TI"} ;TI" ;TI"3# Convert pdf to ps and send it to a printer. ;TI"1# Collect error message of pdftops and lpr. ;TI"pdf_file = "paper.pdf" ;TI"printer = "printer-name" ;TI"err_r, err_w = IO.pipe ;TI"6Open3.pipeline_start(["pdftops", pdf_file, "-"], ;TI"3 ["lpr", "-P#{printer}"], ;TI"- :err=>err_w) {|ts| ;TI" err_w.close ;TI"9 p err_r.read # error messages of pdftops and lpr. ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@>FI" Open3;FcRDoc::NormalModule00PKt] !¿£ÊÊcapture2e-c.rinu„[µü¤U:RDoc::AnyMethod[iI"capture2e:EFI"Open3::capture2e;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"VOpen3.capture2e captures the standard output and the standard error of a command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Mstdout_and_stderr_str, status = Open3.capture2e([env,] cmd... [, opts]) ;T: @format0o; ; [I"GThe arguments env, cmd and opts are passed to Open3.popen3 except ;TI">opts[:stdin_data] and opts[:binmode]. See Process.spawn.;T@o; ; [I"SIf opts[:stdin_data] is specified, it is sent to the command's standard input.;T@o; ; [I"FIf opts[:binmode] is true, internal pipes are set to binary mode.;T@o; ; [I" Example:;T@o; ; [I"# capture make log ;TI"*make_log, s = Open3.capture2e("make");T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"3(*cmd, stdin_data: '', binmode: false, **opts);T@#FI" Open3;FcRDoc::NormalModule00PKt]x[æŸLLpipeline_r-i.rinu„[µü¤U:RDoc::AnyMethod[iI"pipeline_r:EFI"Open3#pipeline_r;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JOpen3.pipeline_r starts a list of commands as a pipeline with a pipe ;TI"2which connects to stdout of the last command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"MOpen3.pipeline_r(cmd1, cmd2, ... [, opts]) {|last_stdout, wait_threads| ;TI" ... ;TI"} ;TI" ;TI"Llast_stdout, wait_threads = Open3.pipeline_r(cmd1, cmd2, ... [, opts]) ;TI" ... ;TI"last_stdout.close ;T: @format0o; ; [I"'Each cmd is a string or an array. ;TI"AIf it is an array, the elements are passed to Process.spawn.;T@o; ; [ I" cmd: ;TI"_ commandline command line string which is passed to a shell ;TI"_ [env, commandline, opts] command line string which is passed to a shell ;TI"b [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) ;TI"h [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) ;TI" ;TI"@Note that env and opts are optional, as for Process.spawn. ;T; 0o; ; [I" Example:;T@o; ; [I"?Open3.pipeline_r("zcat /var/log/apache2/access.log.*.gz", ;TI"C [{"LANG"=>"C"}, "grep", "GET /favicon.ico"], ;TI"- "logresolve") {|o, ts| ;TI" o.each_line {|line| ;TI" ... ;TI" } ;TI"} ;TI" ;TI"2Open3.pipeline_r("yes", "head -10") {|o, ts| ;TI": p o.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n" ;TI"K p ts[0].value #=> # ;TI"> p ts[1].value #=> # ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@8FI" Open3;FcRDoc::NormalModule00PKt]l×Lȯ¯pipeline_w-c.rinu„[µü¤U:RDoc::AnyMethod[iI"pipeline_w:EFI"Open3::pipeline_w;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JOpen3.pipeline_w starts a list of commands as a pipeline with a pipe ;TI"2which connects to stdin of the first command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"MOpen3.pipeline_w(cmd1, cmd2, ... [, opts]) {|first_stdin, wait_threads| ;TI" ... ;TI"} ;TI" ;TI"Lfirst_stdin, wait_threads = Open3.pipeline_w(cmd1, cmd2, ... [, opts]) ;TI" ... ;TI"first_stdin.close ;T: @format0o; ; [I"'Each cmd is a string or an array. ;TI"AIf it is an array, the elements are passed to Process.spawn.;T@o; ; [ I" cmd: ;TI"_ commandline command line string which is passed to a shell ;TI"_ [env, commandline, opts] command line string which is passed to a shell ;TI"b [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) ;TI"h [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) ;TI" ;TI"@Note that env and opts are optional, as for Process.spawn. ;T; 0o; ; [I" Example:;T@o; ; [I"COpen3.pipeline_w("bzip2 -c", :out=>"/tmp/hello.bz2") {|i, ts| ;TI" i.puts "hello" ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@.FI" Open3;FcRDoc::NormalModule00PKt]£'p8 8 popen3-c.rinu„[µü¤U:RDoc::AnyMethod[iI" popen3:EFI"Open3::popen3;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"KOpen stdin, stdout, and stderr streams and start external executable. ;TI"GIn addition, a thread to wait for the started process is created. ;TI"PThe thread has a pid method and a thread variable :pid which is the pid of ;TI"the started process.;To:RDoc::Markup::BlankLineo; ; [I"Block form:;T@o:RDoc::Markup::Verbatim; [ I"MOpen3.popen3([env,] cmd... [, opts]) {|stdin, stdout, stderr, wait_thr| ;TI"8 pid = wait_thr.pid # pid of the started process. ;TI" ... ;TI"G exit_status = wait_thr.value # Process::Status object returned. ;TI"} ;T: @format0o; ; [I"Non-block form:;T@o; ; [ I"Lstdin, stdout, stderr, wait_thr = Open3.popen3([env,] cmd... [, opts]) ;TI"8pid = wait_thr[:pid] # pid of the started process ;TI" ... ;TI"Wstdin.close # stdin, stdout and stderr should be closed explicitly in this form. ;TI"stdout.close ;TI"stderr.close ;TI"Fexit_status = wait_thr.value # Process::Status object returned. ;T; 0o; ; [I"DThe parameters env, cmd, and opts are passed to Process.spawn. ;TI"TA commandline string and a list of argument strings can be accepted as follows:;T@o; ; [I"2Open3.popen3("echo abc") {|i, o, e, t| ... } ;TI"5Open3.popen3("echo", "abc") {|i, o, e, t| ... } ;TI"@Open3.popen3(["echo", "argv0"], "abc") {|i, o, e, t| ... } ;T; 0o; ; [I"]If the last parameter, opts, is a Hash, it is recognized as an option for Process.spawn.;T@o; ; [I"1Open3.popen3("pwd", :chdir=>"/") {|i,o,e,t| ;TI" p o.read.chomp #=> "/" ;TI"} ;T; 0o; ; [I">wait_thr.value waits for the termination of the process. ;TI"?The block form also waits for the process when it returns.;T@o; ; [I"PClosing stdin, stdout and stderr does not wait for the process to complete.;T@o; ; [ I"/You should be careful to avoid deadlocks. ;TI"+Since pipes are fixed length buffers, ;TI">Open3.popen3("prog") {|i, o, e, t| o.read } deadlocks if ;TI"6the program generates too much output on stderr. ;TI"TYou should read stdout and stderr simultaneously (using threads or IO.select). ;TI"IHowever, if you don't need stderr output, you can use Open3.popen2. ;TI"UIf merged stdout and stderr output is not a problem, you can use Open3.popen2e. ;TI"fIf you really need stdout and stderr output as separate strings, you can consider Open3.capture3.;T: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmd, **opts, &block);T@JFI" Open3;FcRDoc::NormalModule00PKt]ê=d–,, capture2-i.rinu„[µü¤U:RDoc::AnyMethod[iI" capture2:EFI"Open3#capture2;TF: privateo:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I">Open3.capture2 captures the standard output of a command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [I"Astdout_str, status = Open3.capture2([env,] cmd... [, opts]) ;T: @format0o; ; [I"GThe arguments env, cmd and opts are passed to Open3.popen3 except ;TI">opts[:stdin_data] and opts[:binmode]. See Process.spawn.;T@o; ; [I"SIf opts[:stdin_data] is specified, it is sent to the command's standard input.;T@o; ; [I"FIf opts[:binmode] is true, internal pipes are set to binary mode.;T@o; ; [I" Example:;T@o; ; [I"6# factor is a command for integer factorization. ;TI"8o, s = Open3.capture2("factor", :stdin_data=>"42") ;TI"p o #=> "42: 2 3 7\n" ;TI" ;TI"1# generate x**2 graph in png using gnuplot. ;TI" gnuplot_commands = <<"End" ;TI" set terminal png ;TI"! plot x**2, "-" with lines ;TI" 1 14 ;TI" 2 1 ;TI" 3 8 ;TI" 4 5 ;TI" e ;TI" End ;TI"Ximage, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true);T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"3(*cmd, stdin_data: '', binmode: false, **opts);T@0FI" Open3;FcRDoc::NormalModule00PKt]…Α??pipeline_rw-c.rinu„[µü¤U:RDoc::AnyMethod[iI"pipeline_rw:EFI"Open3::pipeline_rw;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JOpen3.pipeline_rw starts a list of commands as a pipeline with pipes ;TI"Pwhich connect to stdin of the first command and stdout of the last command.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim; [ I"[Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads| ;TI" ... ;TI"} ;TI" ;TI"Zfirst_stdin, last_stdout, wait_threads = Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) ;TI" ... ;TI"first_stdin.close ;TI"last_stdout.close ;T: @format0o; ; [I"'Each cmd is a string or an array. ;TI"AIf it is an array, the elements are passed to Process.spawn.;T@o; ; [ I" cmd: ;TI"_ commandline command line string which is passed to a shell ;TI"_ [env, commandline, opts] command line string which is passed to a shell ;TI"b [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell) ;TI"h [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell) ;TI" ;TI"@Note that env and opts are optional, as for Process.spawn. ;T; 0o; ; [I"EThe options to pass to Process.spawn are constructed by merging ;TI"5+opts+, the last hash element of the array, and ;TI"?specifications for the pipes between each of the commands.;T@o; ; [I" Example:;T@o; ; [I"=Open3.pipeline_rw("tr -dc A-Za-z", "wc -c") {|i, o, ts| ;TI"F i.puts "All persons more than a mile high to leave the court." ;TI" i.close ;TI" p o.gets #=> "42\n" ;TI"} ;TI" ;TI"EOpen3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs| ;TI" stdin.puts "foo" ;TI" stdin.puts "bar" ;TI" stdin.puts "baz" ;TI"+ stdin.close # send EOF to sort. ;TI"E p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n" ;TI"};T; 0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*cmds, **opts, &block);T@>FI" Open3;FcRDoc::NormalModule00PKt]è¨Á÷77 popen2e-i.rinu„[µü¤PKt]À² ½½ spipeline-i.rinu„[µü¤PKt]OüÊÊmcapture2e-i.rinu„[µü¤PKt]ÄæN²ãã ucapture3-c.rinu„[µü¤PKt]dí[Þ??•pipeline_rw-i.rinu„[µü¤PKt]çøð"ÀÀ#cdesc-Open3.rinu„[µü¤PKt]}i 477 +popen2e-c.rinu„[µü¤PKt]Ú»¦Z8 8 …0popen3-i.rinu„[µü¤PKt]Bzeݯ¯ø:pipeline_w-i.rinu„[µü¤PKt]cÀ ,, æ@capture2-c.rinu„[µü¤PKt]¦Áå>ôôOFpipeline_start-i.rinu„[µü¤PKt]!ð£ï½½ †Npipeline-c.rinu„[µü¤PKt]|HM޼¼ €Wpopen2-i.rinu„[µü¤PKt]¹A&=LLw]pipeline_r-c.rinu„[µü¤PKt]a Iãã ecapture3-i.rinu„[µü¤PKt];F)ž¼¼ "mpopen2-c.rinu„[µü¤PKt]0Xâ¾ôôspipeline_start-c.rinu„[µü¤PKt] !¿£ÊÊP{capture2e-c.rinu„[µü¤PKt]x[æŸLLXpipeline_r-i.rinu„[µü¤PKt]l×Lȯ¯ã†pipeline_w-c.rinu„[µü¤PKt]£'p8 8 ÑŒpopen3-c.rinu„[µü¤PKt]ê=d–,, D—capture2-i.rinu„[µü¤PKt]…Α??­œpipeline_rw-c.rinu„[µü¤PKþ,¥