Getting data from Expect

Hi All,

Can anyone tell me how I can get all the data produced by the command
“less”:
PTY.spawn(“cd some_directory”) do |reader, writer, pid|

wireter.puts “less some_text_file”
# How do I get the content of the whole file?

Also, what is the command to find whether a ruby script has
successfully ssh-ed to a machine:
PTY.spawn(“ssh user@machine”) do |reader, writer, pid|
# How to find out that the login is successful?

I would really really appreciate your help!

Thanks,
Greg