Skip to content

Instantly share code, notes, and snippets.

@MattesGroeger
Last active January 4, 2016 19:09
Show Gist options
  • Save MattesGroeger/8665983 to your computer and use it in GitHub Desktop.
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.
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