On Monday 28 March 2005 07:07 pm, samuel_x_winters_x / hotmail.com wrote:
> The net/ssh code below works fine in irb, but dies when inside a rake
> task.
[... example elided ...]
> Any idea what is going on?

There is an unintended interaction between the FileUtils methods (which rake 
defines at top level for convenience) and the use of method_missing in the 
SSH SyncShell.  

Rake includes the FileUtils methods (e.g. cp, rm_r, install) at the top level 
of the script so that file based actions are easy to write.  The SSH 
SyncShell object uses method_missing to turn ruby method calls into SSH 
commands sent with the send_command method.  Since "pwd" is available at the 
top level, shell.pwd calls that instead of invoking the method_missing 
handler.

The quick workaround is to use send_command directly.  The example would look 
like this:

task :publish do
require 'net/ssh'
Net::SSH.start('svr.com','usr','pwd') do |session|
shell = session.shell.sync
out = shell.send_command("pwd")
puts out.stdout
end
end

Another workaround would be to mark the "pwd" command as private at the top 
level.  This allows the method_missing handler to do its thing without 
interfering with the use of 'pwd' at the top level.  Future versions of Rake 
will do this automatically for you.  But for now you can add the line

  private :pwd

Somewhere in your rakefile.

Does this help?

-- 
-- Jim Weirich    jim / weirichhouse.org     http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct, 
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)