Created
February 25, 2018 18:59
-
-
Save nicholaides/1ad0b65ebeb11a76ea806fbb7434d002 to your computer and use it in GitHub Desktop.
Like FileUtils#sh but lets you specify a file to redirect output to. Helpful for building rake tasks.
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
# Like sh, but | |
# 1. lets you specify a file to redirect output to and | |
# 2. removes the file if there's an error | |
def sh_redirect(*args, out:) | |
sh(*args, { out: out }, {}) do |ok, status| | |
unless ok | |
rm_f out | |
raise "Command failed: `#{args.join(' ')}`\nDeleted `#{out}`" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment