From: Jamis Buck Date: 2005-02-18T00:38:37+09:00 Subject: Re: net::ssh popen3 issue? On 00:09 Fri 18 Feb , ritchie@ipowerhouse.com wrote: > hi > > I'm using popen3 to query a database. I'm returning 20 records but I'm > only getting 5 back. The command executed is a simple psql query to a > pg database so there's not much room for error there. Is there some > kind of timeout or fixed buffer size when using popen3? Thanks for any > help. > > Here's some relevant code: > > records = [] > headings = [] > Commands.session.process.popen3( "sudo bin/get_account" ) { |i,o,e| > > x = o.read > puts x > lines = x.split("\n") > > lines.each_with_index { |l,i| > fields = l.split("|") > if i == 0 > headings = fields > else > if i != 1 # got a line > records << fields > end > end > #puts "line #{i}, fields #{records}" > } > puts "number of lines is #{lines.length}" > } > > tw = headings.length > th = records.length It sounds like it might be a timing issue... there are a lot of those when using the Net::SSH stuff, unfortunately. Perhaps try using the shell.sync service to do it: shell = session.shell.sync result = shell.send_command "sudo bin/get_account" lines = result.stdout ... The asynchronous nature of Net::SSH really wreaks havoc with these kinds of things. The shell.sync service is probably the most robust way I've seen for executing remote commands via ssh, but even it still suffers from some weak areas. If anyone has come up with a clever way to execute remote commands using Net::SSH, I'd love to hear about them. - Jamis -- Jamis Buck jamis_buck@byu.edu http://jamis.jamisbuck.org ------------------------------ "I am Victor of Borge. You will be assimil-nine-ed."