'Git Bash on Windows with Ruby: Waiting for gets() input before printing prompt?
I'm new to programming/Ruby and can't figure out this quirky issue...
Running this Ruby code through Git Bash on Windows:
$ ruby test.rb
puts "Give me input: "
input = gets
puts "You gave me #{input}"
does not print the "Give me input: " string before waiting for input with gets() as it should. Instead it immediately waits for input before printing the prompt and the result. I've tried using $stdout.flush after the prompt puts() but the output remains the same.
Every other terminal I've used works fine though.
Solution 1:[1]
As @user11659763 noted, setting STDOUT.sync = true
fixes the output so that it is always flushed after each call to puts
or print
, as is desired, in Git Bash.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user306479 |