Ruby Puts Not Outputting in Real Time

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



Leave a reply



Submit