Skip to content

Commit

Permalink
Hack for getting stdout, stderr, exit status in 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
mizzy committed Apr 23, 2013
1 parent b3ebd60 commit 043e769
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/serverspec/backend/exec.rb
@@ -1,3 +1,5 @@
require 'open3'

module Serverspec
module Backend
class Exec
Expand All @@ -10,11 +12,17 @@ def commands
end

def do_check(cmd, opts={})
stdout = `#{cmd} 2>&1`
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
#stdout, stderr, status = Open3.capture3(cmd)
{ :stdout => stdout, :stderr => nil,
:exit_status => $?, :exit_signal => nil }
# So get exit status with `command`
`#{cmd} 2>&1`
ret = { :exit_status => $?, :exit_signal => nil }

# Get stdout and stderr
stdin, stdout, stderr = Open3.popen3(cmd)
ret[:stdout] = stdout.read
ret[:stderr] = stderr.read
ret
end

def check_zero(cmd, *args)
Expand Down

0 comments on commit 043e769

Please sign in to comment.