Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ruby的Windows上的Git Bash:在打印提示之前等待gets()输入?_Ruby_Windows_Git Bash - Fatal编程技术网

使用Ruby的Windows上的Git Bash:在打印提示之前等待gets()输入?

使用Ruby的Windows上的Git Bash:在打印提示之前等待gets()输入?,ruby,windows,git-bash,Ruby,Windows,Git Bash,我是编程/Ruby新手,无法解决这个奇怪的问题 在Windows上通过Git Bash运行此Ruby代码: $ruby test.rb puts "Give me input: " input = gets puts "You gave me #{input}" 在使用gets()等待输入之前,不打印“Give me input:”字符串。相反,它会在打印提示和结果之前立即等待输入。我尝试在提示符put()后使用$stdout.flush,但输出保持不变 不过,我使用过的所有其他终端都可以正常

我是编程/Ruby新手,无法解决这个奇怪的问题

在Windows上通过Git Bash运行此Ruby代码:

$ruby test.rb

puts "Give me input: "
input = gets
puts "You gave me #{input}"
在使用gets()等待输入之前,不打印“Give me input:”字符串。相反,它会在打印提示和结果之前立即等待输入。我尝试在提示符put()后使用$stdout.flush,但输出保持不变


不过,我使用过的所有其他终端都可以正常工作。

在程序开始时,在
input=get
STDOUT.sync=true
之前尝试
STDOUT.flush