D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Open3
/
Filename :
capture2-c.ri
back
Copy
U:RDoc::AnyMethod[iI" capture2:ETI"Open3::capture2;TT:publico:RDoc::Markup::Document:@parts[/o:RDoc::Markup::Paragraph; [I"/Basically a wrapper for Open3.popen3 that:;To:RDoc::Markup::BlankLine o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"OCreates a child process, by calling Open3.popen3 with the given arguments ;TI"?(except for certain entries in hash +options+; see below).;To;;0; [o; ; [I"KReturns as string +stdout_s+ the standard output of the child process.;To;;0; [o; ; [I";Returns as +status+ a <tt>Process::Status</tt> object ;TI":that represents the exit status of the child process.;T@o; ; [I"3Returns the array <tt>[stdout_s, status]</tt>:;T@o:RDoc::Markup::Verbatim; [I"5stdout_s, status = Open3.capture2('echo "Foo"') ;TI"<# => ["Foo\n", #<Process::Status: pid 2326047 exit 0>] ;T:@format0o; ; [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"KUnlike Process.spawn, this method waits for the child process to exit ;TI"4before returning, so the caller need not do so.;T@o; ; [I"HIf the first argument is a hash, it becomes leading argument +env+ ;TI""in the call to Open3.popen3; ;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 the call to Open3.popen3; ;TI"Asee {Execution Options}[rdoc-ref:Process@Execution+Options].;T@o; ; [I""The hash +options+ is given; ;TI"<two options have local effect in method Open3.capture2:;T@o;; ;;[o;;0; [o; ; [I"IIf entry <tt>options[:stdin_data]</tt> exists, the entry is removed ;TI"Band its string value is sent to the command's standard input:;T@o;; [I".Open3.capture2('tee', stdin_data: 'Foo') ;TI" ;TI":# => ["Foo", #<Process::Status: pid 2326087 exit 0>] ;T;0o;;0; [o; ; [I"JIf entry <tt>options[:binmode]</tt> exists, the entry is removed and ;TI"1the internal streams are set to binary mode.;T@o; ; [I":The single required argument is one of the following:;T@o;; ;;[o;;0; [o; ; [I"'+command_line+ if it is a string, ;TI"Fand if it begins with a shell reserved word or special built-in, ;TI"2or if it contains one or more metacharacters.;To;;0; [o; ; [I"+exe_path+ otherwise.;T@o; ; [I"#<b>Argument +command_line+</b>;T@o; ; [I"P\String argument +command_line+ is a command line to be passed to a shell; ;TI"Nit must begin with a shell reserved word, begin with a special built-in, ;TI" or contain meta characters:;T@o;; [I"KOpen3.capture2('if true; then echo "Foo"; fi') # Shell reserved word. ;TI"<# => ["Foo\n", #<Process::Status: pid 2326131 exit 0>] ;TI"@Open3.capture2('echo') # Built-in. ;TI"9# => ["\n", #<Process::Status: pid 2326139 exit 0>] ;TI"OOpen3.capture2('date > date.tmp') # Contains meta character. ;TI"7# => ["", #<Process::Status: pid 2326174 exit 0>] ;T;0o; ; [I"MThe command line may also contain arguments and options for the command:;T@o;; [I""Open3.capture2('echo "Foo"') ;TI"<# => ["Foo\n", #<Process::Status: pid 2326183 exit 0>] ;T;0o; ; [I"<b>Argument +exe_path+</b>;T@o; ; [I"1Argument +exe_path+ is one of the following:;T@o;; ;;[o;;0; [o; ; [I"3The string path to an executable to be called.;To;;0; [o; ; [I"<A 2-element array containing the path to an executable ;TI"Dand the string to be used as the name of the executing process.;T@o; ; [I" Example:;T@o;; [I"%Open3.capture2('/usr/bin/date') ;TI"X# => ["Fri Sep 29 01:00:39 PM CDT 2023\n", #<Process::Status: pid 2326222 exit 0>] ;T;0o; ; [I"PRuby invokes the executable directly, with no shell and no shell expansion:;T@o;; [I";Open3.capture2('doesnt_exist') # Raises Errno::ENOENT ;T;0o; ; [I"CIf one or more +args+ is given, each is an argument or option ;TI"$to be passed to the executable:;T@o;; [ I"#Open3.capture2('echo', 'C #') ;TI"<# => ["C #\n", #<Process::Status: pid 2326267 exit 0>] ;TI".Open3.capture2('echo', 'hello', 'world') ;TI"C# => ["hello world\n", #<Process::Status: pid 2326299 exit 0>];T;0: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below0I"�Open3.capture2([env, ] command_line, options = {}) -> [stdout_s, status] Open3.capture2([env, ] exe_path, *args, options = {}) -> [stdout_s, status] ;T0[ I"(*cmd);T@�FI" Open3;TcRDoc::NormalModule00