Wednesday, May 21, 2008

Ruby: Debugging backticks

I needed to knock up a Ruby script recently that orchestrated some external processes using backticks. However something was going wrong and I need to temporarily peek into the inputs and outputs of the external programs. Ruby bend-ability to the rescue:
module Kernel
  alias_method :real_backticks, :'`'

  def `(cmd) 
    puts "`#{cmd}` => #{output = real_backticks(cmd)}"
    output
  end
end

No comments: