D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Open3
/
Filename :
popen2e-i.ri
back
Copy
U:RDoc::AnyMethod[iI"popen2e:ETI"Open3#popen2e;TF:privateo:RDoc::Markup::Document:@parts[8o: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"PCreates a child process, by calling Process.spawn with the given arguments.;To;;0; [o; ; [I"3Creates streams +stdin+, +stdout_and_stderr+, ;TI"Gwhich are the standard input and the merge of the standard output ;TI"5and standard error streams in the child process.;To;;0; [o; ; [I"LCreates thread +wait_thread+ that waits for the child process to exit; ;TI"?the thread has method +pid+, which returns the process ID ;TI"of the child process.;T@o; ; [I",With no block given, returns the array ;TI"7<tt>[stdin, stdout_and_stderr, wait_thread]</tt>. ;TI">The caller should close each of the two returned streams.;T@o:RDoc::Markup::Verbatim; [I"Cstdin, stdout_and_stderr, wait_thread = Open3.popen2e('echo') ;TI"N# => [#<IO:fd 6>, #<IO:fd 7>, #<Process::Waiter:0x00007f7577da4398 run>] ;TI"stdin.close ;TI"stdout_and_stderr.close ;TI"$wait_thread.pid # => 2274600 ;TI"Cwait_thread.value # => #<Process::Status: pid 2274600 exit 0> ;T:@format0o; ; [ I"BWith a block given, calls the block with the three variables ;TI"'(two streams and the wait thread) ;TI"+and returns the block's return value. ;TI"+The caller need not close the streams:;T@o;; [I"FOpen3.popen2e('echo') do |stdin, stdout_and_stderr, wait_thread| ;TI" p stdin ;TI" p stdout_and_stderr ;TI" p wait_thread ;TI" p wait_thread.pid ;TI" p wait_thread.value ;TI" end ;T;0o; ; [I"Output:;T@o;; [ I"#<IO:fd 6> ;TI"#<IO:fd 7> ;TI"1#<Process::Waiter:0x00007f75777578c8 sleep> ;TI" 2274763 ;TI",#<Process::Status: pid 2274763 exit 0> ;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"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 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 the call to Process.spawn; ;TI"Asee {Execution Options}[rdoc-ref:Process@Execution+Options].;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"\Open3.popen2e('if true; then echo "Foo"; fi') {|*args| p args } # Shell reserved word. ;TI"QOpen3.popen2e('echo') {|*args| p args } # Built-in. ;TI"`Open3.popen2e('date > date.tmp') {|*args| p args } # Contains meta character. ;T;0o; ; [I"*Output (similar for each call above):;T@o;; [I"W# => [#<IO:(closed)>, #<IO:(closed)>, #<Process::Waiter:0x00007f7577d8a1f0 dead>] ;T;0o; ; [I"MThe command line may also contain arguments and options for the command:;T@o;; [I"BOpen3.popen2e('echo "Foo"') { |i, o_and_e, t| o_and_e.gets } ;TI" "Foo\n" ;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"EOpen3.popen2e('/usr/bin/date') { |i, o_and_e, t| o_and_e.gets } ;TI".# => "Thu Sep 28 01:58:45 PM CDT 2023\n" ;T;0o; ; [I"PRuby invokes the executable directly, with no shell and no shell expansion:;T@o;; [I"[Open3.popen2e('doesnt_exist') { |i, o_and_e, t| o_and_e.gets } # 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"COpen3.popen2e('echo', 'C #') { |i, o_and_e, t| o_and_e.gets } ;TI"# => "C #\n" ;TI"NOpen3.popen2e('echo', 'hello', 'world') { |i, o_and_e, t| o_and_e.gets } ;TI"# => "hello world\n" ;T;0o; ; [I" Related:;T@o;; ;;[o;;0; [o; ; [I"HOpen3.popen2: Makes the standard input and standard output streams ;TI"9of the child process available as separate streams, ;TI"1with no access to the standard error stream.;To;;0; [o; ; [I">Open3.popen3: Makes the standard input, standard output, ;TI" and standard error streams ;TI"8of the child process available as separate streams.;T: @fileI"lib/open3.rb;T:0@omit_headings_from_table_of_contents_below0I"�Open3.popen2e([env, ] command_line, options = {}) -> [stdin, stdout_and_stderr, wait_thread] Open3.popen2e([env, ] exe_path, *args, options = {}) -> [stdin, stdout_and_stderr, wait_thread] Open3.popen2e([env, ] command_line, options = {}) {|stdin, stdout_and_stderr, wait_thread| ... } -> object Open3.popen2e([env, ] exe_path, *args, options = {}) {|stdin, stdout_and_stderr, wait_thread| ... } -> object ;T0[ I"(*cmd, &block);T@�FI" Open3;TcRDoc::NormalModule00