diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-26 16:47:30 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-26 16:47:30 +0000 |
commit | d95d20903361bbdb62cec068ab6afd7e850b1ce5 (patch) | |
tree | a06b4c1bae4c1c2577385aeb5c5c5d6fa95331c4 /lib | |
parent | c42a631063e79fab2369c1983a6f2a075b584f62 (diff) | |
download | ruby-d95d20903361bbdb62cec068ab6afd7e850b1ce5.tar.gz |
* lib/open3.rb (Open3.popen3w): removed.
(Open3.popen3): notice wait_thr.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/open3.rb | 57 |
1 files changed, 15 insertions, 42 deletions
diff --git a/lib/open3.rb b/lib/open3.rb index ada2b4fbd8..f707f55409 100644 --- a/lib/open3.rb +++ b/lib/open3.rb @@ -9,65 +9,38 @@ # # -# Open3 grants you access to stdin, stdout, and stderr when running another -# program. Example: +# Open3 grants you access to stdin, stdout, stderr and a thread to wait the +# child process when running another program. +# +# Example: # # require "open3" # include Open3 # -# stdin, stdout, stderr = popen3('nroff -man') +# stdin, stdout, stderr, wait_thr = popen3('nroff -man') # -# If the exit status of the child process is required, Open3.popen3w is usable. +# Open3.popen3 can also take a block which will receive stdin, stdout, +# stderr and wait_thr as parameters. +# This ensures stdin, stdout and stderr are closed and +# the process is terminated once the block exits. # -# Open3.popen3 can also take a block which will receive stdin, stdout and -# stderr as parameters. This ensures stdin, stdout and stderr are closed -# once the block exits. Example: +# Example: # # require "open3" # -# Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... } +# Open3.popen3('nroff -man') { |stdin, stdout, stderr, wait_thr| ... } # module Open3 # # Open stdin, stdout, and stderr streams and start external executable. - # - # Non-block form: - # - # stdin, stdout, stderr = Open3.popen3(cmd) - # ... - # stdin.close # stdin, stdout and stderr should be closed in this form. - # stdout.close - # stderr.close - # - # Block form: - # - # Open3.popen3(cmd) { |stdin, stdout, stderr| ... } - # # stdin, stdout and stderr is closed automatically in this form. - # - # The parameter +cmd+ is passed directly to Kernel#spawn. - # - def popen3(*cmd) - if defined? yield - popen3w(*cmd) {|stdin, stdout, stderr, wait_thr| - yield stdin, stdout, stderr - } - else - stdin, stdout, stderr, wait_thr = popen3w(*cmd) - return stdin, stdout, stderr - end - end - module_function :popen3 - - # - # Open stdin, stdout, and stderr streams and start external executable. # In addition, a thread for waiting the started process is noticed. # The thread has a thread variable :pid which is the pid of the started # process. # # Non-block form: # - # stdin, stdout, stderr, wait_thr = Open3.popen3w(cmd) + # stdin, stdout, stderr, wait_thr = Open3.popen3(cmd) # pid = wait_thr[:pid] # pid of the started process. # ... # stdin.close # stdin, stdout and stderr should be closed in this form. @@ -77,7 +50,7 @@ module Open3 # # Block form: # - # Open3.popen3w(cmd) { |stdin, stdout, stderr, wait_thr| ... } + # Open3.popen3(cmd) { |stdin, stdout, stderr, wait_thr| ... } # # The parameter +cmd+ is passed directly to Kernel#spawn. # @@ -86,7 +59,7 @@ module Open3 # # Closing stdin, stdout and stderr does not wait the process. # - def popen3w(*cmd) + def popen3(*cmd) pw = IO::pipe # pipe[0] for read, pipe[1] for write pr = IO::pipe pe = IO::pipe @@ -109,7 +82,7 @@ module Open3 end pi end - module_function :popen3w + module_function :popen3 end if $0 == __FILE__ |