Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I echo the output from Ruby shell scripts in chunks?

I'm setting up a mini deploy system with Ruby and Sinatra and Shell scripts, and when I trigger a deploy script I'd like ruby to continue to echo the output from the following:

post '/' do
  `/home/deploy/deploy.sh`
end

How can I ensure that Ruby will echo the output and send a chunked response (so that the content can continue to load)?

Thanks!

like image 266
crockpotveggies Avatar asked Aug 06 '26 10:08

crockpotveggies


1 Answers

You have two distinct problems here:

  1. How to stream-receive the output of the command while it is running?
    • You want to use IO.popen.
  2. Within Sinatra, how do I stream a response to the user?
    • You want to use Sinatra 1.3's stream. (See also this question.)
like image 138
Phrogz Avatar answered Aug 07 '26 22:08

Phrogz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!