Skip to content

Instantly share code, notes, and snippets.

@elcontrastador
Created September 4, 2011 06:18
Show Gist options
  • Save elcontrastador/1192373 to your computer and use it in GitHub Desktop.
Save elcontrastador/1192373 to your computer and use it in GitHub Desktop.
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