Skip to content

Instantly share code, notes, and snippets.

@elcontrastador
Created September 4, 2011 06:38
Show Gist options
  • Save elcontrastador/1192404 to your computer and use it in GitHub Desktop.
Save elcontrastador/1192404 to your computer and use it in GitHub Desktop.
def _syscall_raw(cmd_str)
outputs = Hash.new
Open3.popen3(cmd_str) do |stdin,stdout,stderr,wait_thr|
outputs[:stdout] = stdout.read
outputs[:stderr] = stderr.read
outputs[:pid] = wait_thr.value.pid
outputs[:exitstatus] = wait_thr.value.exitstatus
end
outputs
end
def self.syscall(cmd_str,success_retval=nil,dryrun_opts=nil)
if dryrun
outputs = dryrun_opts
else
outputs = _syscall_raw(cmd_str)
end
raise_str = <<-STR
Command: \'#{cmd_str}\' failed!
Exitstatus => #{outputs[:wait_thr].value}
Stderr => #{outputs[:stderr]}
STR
if success_retval
unless outputs[:exitstatus] == success_retval
raise raise_str
end
elsif not outputs[:exitstatus] == 0
raise raise_str
end
outputs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment