Skip to content

Instantly share code, notes, and snippets.

@gouthamvel
Created October 11, 2011 06:12
Show Gist options
  • Save gouthamvel/1277407 to your computer and use it in GitHub Desktop.
Save gouthamvel/1277407 to your computer and use it in GitHub Desktop.
command execution using open3, with a post execution block
def cmd_exe(cmd, &block)
output = nil
log_to_scribe("JR-ncpr-upload"," executing command #{cmd}")
Open3.popen3(cmd) do |stdin, stdout, stderr|
output = stdout.readlines
error = stderr.readlines
unless error.empty?
p "#{cmd} Failed "
log_to_scribe("JR-ncpr-upload","#{cmd} Failed, with error #{error.to_s}")
yield false if block_given?
raise JobRunnerErrors::JobFailed("#{cmd} Failed, with error #{error.to_s}")
end
end
yield true if block_given?
output
end
@gouthamvel
Copy link
Author

on line 11 the control breaks and comes out ... hopefully that's not a good ruby way of doing it !

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