D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Open3
/
Filename :
pipeline_w-i.ri
back
Copy
U:RDoc::AnyMethod[iI"pipeline_w:ETI"Open3#pipeline_w;TF:privateo:RDoc::Markup::Document:@parts[#o:RDoc::Markup::Paragraph; [I"Basically a wrapper for ;TI"-{Process.spawn}[rdoc-ref:Process.spawn] ;TI" that:;To:RDoc::Markup::BlankLine o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I":Creates a child process for each of the given +cmds+ ;TI"by calling Process.spawn.;To;;0; [o; ; [I"JPipes the +stdout+ from each child to the +stdin+ of the next child, ;TI"Qor, for the first child, pipes the caller's +stdout+ to the child's +stdin+.;T@o; ; [I";The method does not wait for child processes to exit, ;TI"so the caller must do so.;T@o; ; [I"?With no block given, returns a 2-element array containing:;T@o;; ;;[o;;0; [o; ; [I"3The +stdin+ stream of the first child process.;To;;0; [o; ; [I"AAn array of the wait threads for all of the child processes.;T@o; ; [I" Example:;T@o:RDoc::Markup::Verbatim; [I"Dfirst_stdin, wait_threads = Open3.pipeline_w('sort', 'cat -n') ;TI"o# => [#<IO:fd 7>, [#<Process::Waiter:0x000055e8de928278 run>, #<Process::Waiter:0x000055e8de923e80 run>]] ;TI"'first_stdin.puts("foo\nbar\nbaz") ;TI"+first_stdin.close # Send EOF to sort. ;TI"(wait_threads.each do |wait_thread| ;TI" wait_thread.join ;TI" end ;T:@format0o; ; [I"Output:;T@o;; [I"1 bar ;TI"2 baz ;TI"3 foo ;T;0o; ; [I"AWith a block given, calls the block with the +stdin+ stream ;TI"!of the first child process, ;TI"(and an array of the wait processes:;T@o;; [I"GOpen3.pipeline_w('sort', 'cat -n') do |first_stdin, wait_threads| ;TI") first_stdin.puts("foo\nbar\nbaz") ;TI"- first_stdin.close # Send EOF to sort. ;TI"* wait_threads.each do |wait_thread| ;TI" wait_thread.join ;TI" end ;TI" end ;T;0o; ; [I"Output:;T@o;; [I"1 bar ;TI"2 baz ;TI"3 foo ;T;0o; ; [I"LLike Process.spawn, this method has potential security vulnerabilities ;TI"%if called with untrusted input; ;TI"Psee {Command Injection}[rdoc-ref:command_injection.rdoc@Command+Injection].;T@o; ; [I"HIf the first argument is a hash, it becomes leading argument +env+ ;TI"$in each call to Process.spawn; ;TI"Isee {Execution Environment}[rdoc-ref:Process@Execution+Environment].;T@o; ; [I"LIf the last argument is a hash, it becomes trailing argument +options+ ;TI"$in each call to Process.spawn; ;TI"Asee {Execution Options}[rdoc-ref:Process@Execution+Options].;T@o; ; [I"1Each remaining argument in +cmds+ is one of:;T@o;; ;;[o;;0; [o; ; [I"GA +command_line+: a string that begins with a shell reserved word ;TI"Aor special built-in, or contains one or more metacharacters.;To;;0; [o; ; [I"BAn +exe_path+: the string path to an executable to be called.;To;;0; [o; ; [I"<An array containing a +command_line+ or an +exe_path+, ;TI">along with zero or more string arguments for the command.;T@o; ; [I"aSee {Argument command_line or exe_path}[rdoc-ref:Process@Argument+command_line+or+exe_path].;T: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below0I"ROpen3.pipeline_w([env, ] *cmds, options = {}) -> [first_stdin, wait_threads] ;T0[ I"(*cmds, &block);T@FI" Open3;TcRDoc::NormalModule00