# Having trouble formatting output stream, when executing remote program

**URL:** <https://www.ruby-forum.com/t/having-trouble-formatting-output-stream-when-executing-remote-program/234515>\
**Category:** Ruby\
**Created:** [March 10, 2015, 6:09pm UTC](https://www.ruby-forum.com/t/having-trouble-formatting-output-stream-when-executing-remote-program/234515 "2015-03-10T18:09:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [March 10, 2015, 6:09pm UTC](https://www.ruby-forum.com/t/having-trouble-formatting-output-stream-when-executing-remote-program/234515/1 "2015-03-10T18:09:33Z")

</div>

Hi all,

I’m a bit stumped on how to handle formatting the output of a remotely  
executed file if anyone has suggestions or pointers. Executing the  
command ‘db-update.sh’ on my remote box, gives me a nice formatted  
output like this:

App Deleted:  
Trial Counter: 2  
Trial Details ID: 0

* * *

But if I execute the following piece of code in a .rb file:

cmd = “db-update.sh”  
stdout = “”  
session.exec!(cmd) do |channel, stream, data|  
stdout \<\< data if stream == :stdout  
end  
print ‘Result: %s’ % stdout

I get this:

“App Deleted:\n PreTrial Counter: 2\n Trial Details ID:  
0\n------------------- ------------------- --------------------\n”

I’ve tried multiple variations of printing the result but I’m not  
understanding why it’s not converting the \n to a newline but assume  
it’s to do with how I’m processing the output?
