Ruby puts not outputting in real time
Try adding a STDOUT.sync = true
. You could also try STDOUT.flush
after the puts
. Some more info here.
Ruby: Printing system output in real time?
According to the documentation you should be able to use the output stream given in the block:
Open3.popen3('/path/file_converter.sh', file_list, output_format) do |_,out,_,_|
out.each_line do |line|
puts line
end
end
Ruby shell script realtime output
You can always execute this in Ruby:
system("sh", "script.sh")
Note it's important to specify how to execute this unless you have a proper #!/bin/sh
header as well as the execute bit enabled.
How do I print output of exec() in realtime?
If you don't need for your code to see stdout, and it's sufficient that a human sees it, than system is fine. If you need your code to see it, there are numerous solutions, popen being the simplest, giving your code access to stdout, and Open3 giving your code access to both stdout and stderr. See: Ruby Process Management
Real-time output of a rake task with popen3
Adding $stdout.sync = true
at the beginning of the rake task solved it.
Why does sleep in a thread have no puts output?
Seems like your output is buffered ($stdout.sync
defaults to false
). To flush all output immediately, start your script with:
$stdout.sync = true
Why is Ruby STDOUT buffering when I don't expect it to?
As @Ry points out in the comments, $stdout.sync
is true
by default in IRB, but this is not necessarily the same for scripts.
So you should set $stdout.sync = true
to be sure to prevent buffering.
Related Topics
Select Checkbox Pass Array in Ruby on Rails
How Do Version Numbers Work for Mri Ruby
How to Count Existing Instances of a Class in Ruby
Unpermitted Parameters for Dynamic Forms in Rails 4
Possible to Use Stylesheet.Css.Erb in Rails
Integrating @Font-Face Files into Rails Asset Pipeline
How to Change the Default Value of a Struct Attribute
Getting a List of Classes That Include a Module
Does Ruby Have Syntax for Safe Navigation Operator of Nil Values, Like in Groovy
Capistrano and API Keys in Env Variables
How to Get Http Headers Before Downloading with Ruby's Openuri
Undefined Method (Nomethoderror) Ruby
How to Get the Final Url After Redirects Using Ruby
Errno::Eaccess: Permission Denied @ Dir_S_Mkdir
What Is the Preferred Way of Performing Non Blocking I/O in Ruby