Last active
January 4, 2016 19:09
-
-
Save MattesGroeger/8665983 to your computer and use it in GitHub Desktop.
Run commands from Ruby (e.g. Rakefile) with real time output and exiting on non-0 exit codes.
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
desc 'Build' | |
task :build do | |
run("xbuild Project.sln", "Build failed") | |
run("nunit-console Tests/bin/Debug/Project-Tests.dll", "Tests failed") | |
run("mono Tests/vendor/NSpecRunner.exe Tests/bin/Debug/Project-Tests.dll", "Specs failed") | |
end | |
task :default => :demo | |
# This is the important method | |
def run(command, message) | |
puts "\n==== Run Command: `#{command}` ====\n\n" | |
process = IO.popen(command) do |io| | |
while line = io.gets | |
puts line | |
end | |
io.close | |
end | |
fail message if $?.to_i != 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment