Shane Stillwell
Shane Stillwell

Reputation: 3258

How to print to stdout from system command in Rake?

I have the following Rakefile

desc "Runs tests"
namespace :test do
    task :api do
        `mocha`
    end
end

When I run the command rake test:api, I don't get the nice output of dots that I would if I just ran the command mocha.

How do I print the output of a command real-time in a rake task?

Upvotes: 1

Views: 6670

Answers (1)

knut
knut

Reputation: 27885

You can just put the output:

puts `mocha`

The backticks ` are calling the command mocha and return the output of the command.

You may also use %x{}:

puts %x{mocha}

Or you use system:

system('mocha')

Or you store the output for later use in a variable:

output = `mocha`
puts output

Upvotes: 6

Related Questions