n_x_l
n_x_l

Reputation: 1610

Execute commands and print their output

Is there a way in ruby to execute a command line utility and have its output displayed in real time, something like myrubyscript rspec, where myrubyscript runs rspec and immediately prints output as it receives it from rspec?

Currently, if I invoke rspec with backticks or system, I don't see the rspec output immediately. Rather, it prints at the end.

Preferably, I want the solution to have block form, so that I run code before and after I exec the passed argument.

Upvotes: 0

Views: 67

Answers (1)

sawa
sawa

Reputation: 168249

Use Open3.popen3.

require "open3"
Open3.popen3...

Upvotes: 1

Related Questions