https://github.com/wincent/wopen3
Open3 replacement
https://github.com/wincent/wopen3
Last synced: 3 months ago
JSON representation
Open3 replacement
- Host: GitHub
- URL: https://github.com/wincent/wopen3
- Owner: wincent
- License: bsd-2-clause
- Created: 2009-05-13T22:08:21.000Z (about 17 years ago)
- Default Branch: master
- Last Pushed: 2024-03-01T17:00:37.000Z (over 2 years ago)
- Last Synced: 2025-01-05T15:43:34.758Z (over 1 year ago)
- Language: Ruby
- Homepage: http://www.wincent.com/a/products/walrus/wopen3/
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
- License: LICENSE.txt
Awesome Lists containing this project
README
Wopen3 is a replacement for Open3. Unlike Open3, Wopen3 does not throw away
the exit code of the executed (grandchild) process. Only a child process is
spawned and the exit status is returned in $? as normal.
Usage example:
result, errors = '', ''
Wopen3.popen3('git', 'log') do |stdin, stdout, stderr|
threads = []
threads << Thread.new(stdout) do |out|
out.each { |line| result << line }
end
threads << Thread.new(stderr) do |err|
err.each { |line| errors << line }
end
threads.each { |thread| thread.join }
end
status = $?.exitstatus
raise "Non-zero exit status #{status}" if status != 0
As this is such a common usage pattern, a 'system' method is provided as a
convenience:
result = Wopen3.system('git', 'log')
result.success? # => true
result.status # => 0
result.stderr # => ''
result.stdout # => 'commit 491411b3...'