Ruby Puma + Sinatra streaming output of command

I have a Puma app that, when you enter an IP address and choose to traceroute it by clicking the checkbox, it will perform a traceroute. However, instead of waiting for traceroute to run and posting the result to the user (which can take awhile), I would like to stream the output per line as it runs.

Code below (the app in reality does more but for the sake of this question I have simplified it) :


class Pumatra < Sinatra::Base

    get '/' do
        erb :index

    post '/run' do

   get'/traceroute_results' do
                @traceroute_header = "<br>TCP Traceroute results:"
                  IO.popen("traceroute -4 -w3 #{@ipaddress}") do |io|
                        io.each do |line|
                        @traceroute_result = line
                        erb :traceroute_results


And my views/index.erb file contains this (showing you guys only the relevant bits):

        <div class="checkbox">
            <label><input type="checkbox" id="traceroute" 

        <!-- Start Results block -->
        <section id="results_block" style="display:none;" class="l_panel bg_color_white l_relative">
            <div id="traceroute_results" style="display:none;" class="l_grid"></div>
        <!-- End Results block -->

And lastly, here is my traceroute_results.erb

<%= out %>

Unfortunately I am still receiving nothing when the url loads. I can tell its performing the traceroute because it takes awhile before the result comes back, but it comes back empty.

Really really appreciate anyone’s help and patience in this. I’m running Ruby Puma with Sinatra. Can anyone run this successfully in such a setup? I havent been able to find examples with Sinatra that actually works in the puma context… :frowning:

Thanks, J

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs