Created
September 4, 2011 06:18
-
-
Save elcontrastador/1192373 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Linux | |
module User | |
def self.syscall(cmd_str,success_retval=nil,dryrun_opts=nil) | |
return dryrun_opts if dryrun_opts | |
outputs = Hash.new | |
Open3.popen3(cmd_str) do |stdin,stdout,stderr,wait_thr| | |
outputs[:stdout] = stdout.read | |
outputs[:stderr] = stderr.read | |
outputs[:wait_thr] = wait_thr | |
end | |
raise_str = <<-STR | |
Command: \'#{cmd_str}\' failed! | |
Exitstatus => #{outputs[:wait_thr].value} | |
Stderr => #{outputs[:stderr]} | |
STR | |
if success_retval | |
unless outputs[:wait_thr].value.exitstatus == success_retval | |
raise raise_str | |
end | |
elsif not outputs[:wait_thr].value.success? | |
raise raise_str | |
end | |
outputs | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment