Skip to content

Instantly share code, notes, and snippets.

@jhoblitt
Created September 12, 2013 20:24
Show Gist options
  • Save jhoblitt/6543236 to your computer and use it in GitHub Desktop.
Save jhoblitt/6543236 to your computer and use it in GitHub Desktop.
Testing `$?` with `open3#popen3`
#!/usr/bin/env ruby
require 'open3'
cmd = 'ls not-a-real-path'
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
end
p $?
exit_status = nil
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
exit_status = wait_thr.value
end
p exit_status
$ rvm use 1.9.3
Using /home/jhoblitt/.rvm/gems/ruby-1.9.3-p448
$ ruby --version
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
$ ruby exitstatus_test.rb
nil
#<Process::Status: pid 1163 exit 2>
$ rvm use 2.0.0
Using /home/jhoblitt/.rvm/gems/ruby-2.0.0-p247
$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
$ ruby exitstatus_test.rb
nil
#<Process::Status: pid 1313 exit 2>
@carlossg
Copy link

$ rvm use 1.9.3
Using /Users/csanchez/.rvm/gems/ruby-1.9.3-p448
$ ruby exitstatus_test.rb
nil
#<Process::Status: pid 72645 exit 1>
$ rvm use ruby-2.0.0-p195
Using /Users/csanchez/.rvm/gems/ruby-2.0.0-p195
$ ruby exitstatus_test.rb
nil
#<Process::Status: pid 72885 exit 1>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment