Created
October 11, 2011 06:12
-
-
Save gouthamvel/1277407 to your computer and use it in GitHub Desktop.
command execution using open3, with a post execution block
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on line 11 the control breaks and comes out ... hopefully that's not a good ruby way of doing it !