4

I've created a Capistrano task to execute a rake command. I plan to redirect the output (STDOUT) to a file. E.g.

cap production invoke:rake TASK=mytask > out

This works, but my output includes some additional Capistrano status output, e.g.

00:00 invoke:rake 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake mytask ... ✔ 01 ubuntu@mydomain.com 11.399s

Is there any way to suppress this?

Felix Livni
  • 1,164
  • 13
  • 24

2 Answers2

0

It's probably stderr output. If so, you can redirect standard error to standard out like so:

cap production invoke:rake TASK=mytask > out 2>&1
will_in_wi
  • 2,623
  • 1
  • 16
  • 21
0

Okay, so I think I figured out a pretty good solution.

The key was to use capture (not documented in Capistrano 3.x, but still works). https://github.com/capistrano/capistrano-2.x-docs/blob/master/2.x-DSL-Action-Inspection-Capture.md

namespace :invoke do
  desc "Execute a rake task on a remote server"
  task :rake do
    if ENV['TASK']
      on roles(:app) do
        with rails_env: fetch(:rails_env) do
          puts capture :rake, ENV['TASK']
        end
      end
    else
      puts "\n\nFailed! You need to specify the 'TASK' parameter!",
          "Usage: cap <stage> invoke:rake TASK=your:task"
    end
  end
end
Felix Livni
  • 1,164
  • 13
  • 24