Hello, anybody here? :-)
I have a trivial patch for consideration. It generalises process#popen3 and
process#open so that they can work with a shell service; this is done if you
pass in a nil command name.
Regards,
Brian.
-------------- next part --------------
--- lib/net/ssh/service/process/open.rb.orig 2007-09-24 11:14:25.000000000 +0100
+++ lib/net/ssh/service/process/open.rb 2007-09-24 11:16:12.000000000 +0100
@@ -38,7 +38,7 @@
# attempt to execute the given command. If a block is given, the
# manager will be yielded to the block, and the constructor will not
# return until all channels are closed.
- def initialize( connection, log, command )
+ def initialize( connection, log, command=nil )
@log = log
@command = command
@channel = connection.open_channel(
@@ -129,7 +129,11 @@
def do_confirm( channel )
channel.on_success(&method(:do_exec_success))
channel.on_failure(&method(:do_exec_failure))
- channel.exec @command, true
+ if @command
+ channel.exec @command, true
+ else
+ channel.send_request "shell", nil, true
+ end
end
# Invoked when the invocation of the command has been successful.
@@ -151,7 +155,7 @@
@on_failure.call( self, nil )
else
raise Net::SSH::Exception,
- "could not execute process (#{@command})"
+ @command ? "could not execute process (#{@command})"
: "could not start shell"
end
end
--- lib/net/ssh/service/process/popen3.rb.orig 2007-09-24 11:14:29.000000000
+0100
+++ lib/net/ssh/service/process/popen3.rb 2007-09-24 11:15:02.000000000 +0100
@@ -40,7 +40,7 @@
# is not given, the input, output, and error channels are returned
# and the process *might* not terminate until the session itself
# terminates.
- def popen3( command )
+ def popen3( command=nil )
@connection.open_channel( "session" ) do |chan|
chan.on_success do |ch|
@@ -60,7 +60,11 @@
chan.close
end
- chan.exec command, true
+ if command
+ chan.exec command, true
+ else
+ chan.send_request "shell", nil, true
+ end
end
@connection.loop
--- lib/net/ssh/service/process/driver.rb.orig 2007-09-24 11:21:35.000000000
+0100
+++ lib/net/ssh/service/process/driver.rb 2007-09-24 11:22:04.000000000 +0100
@@ -126,7 +126,7 @@
@handlers = handlers
end
- def open( command )
+ def open( command=nil )
@log.debug "opening ''#{command}''" if
@log.debug?
process = @handlers[ :open ].call( command )
@@ -139,7 +139,7 @@
process
end
- def popen3( command, &block )
+ def popen3( command=nil, &block )
@log.debug "popen3 ''#{command}''" if
@log.debug?
mgr = @handlers[ :popen3 ]
mgr.popen3( command, &block )