The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Capturing Output in Capistrano

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jonathan Weiss

Posts: 146
Nickname: jweiss
Registered: Jan, 2006

Jonathan Weiss is a Ruby and BSD enthusiast
Capturing Output in Capistrano Posted: Sep 28, 2007 1:32 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jonathan Weiss.
Original Post: Capturing Output in Capistrano
Feed Title: BlogFish
Feed URL: http://blog.innerewut.de/feed/atom.xml
Feed Description: Weblog by Jonathan Weiss about Unix, BSD, security, Programming in Ruby, Ruby on Rails and Agile Development.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jonathan Weiss
Latest Posts From BlogFish

Advertisement

A common question about Capistrano tasks is how to capture the output of a task. By default Capistrano will just execute your command and ignore any output.

But sometimes you want to capture and log the output. There is no easy command to do this right now, you have to use the SSH channels:

run "cat /etc/passwd " do |ch, stream, data|
  if stream == :err
    logger.debug "capured output on STDERR: #{data}"
  else # stream == :out
    logger.debug "capured output on STDOUT: #{data}"
  end
end

You can even send data back depending on the captured output:

run "mysql -u root my_database -p < /tmp/dump.sql" do |ch, stream, data|
  if data =~ /password:/
    ch.send_data(root_password)
  end
end

Using this technique you can store command output in the Webistrano log or just print it if you are using stock Capistrano.

Read: Capturing Output in Capistrano

Topic: En Excel 77,1*850 = 100.000 Previous Topic   Next Topic Topic: Tweets on 2007-09-26

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use