I have a Windows laptop and I just recently installed Git, choosing to use Git Bash as my terminal because I am more familiar with the commands. I've installed Ruby but when I try to run this sample program the terminal executes the 'gets' method and then the 'puts'
The following code
puts("Welcome to Calculator")
puts("What's the first number")
number1=gets
puts number1
When run from Git Bash results in this interaction with the terminal
2
Welcome to Calculator!
What's the first number?
2
instead of
Welcome to Calculator!
What's the first number?
2
2
I've tested it in a different environment and the program works fine. Is the problem caused by trying to use Git Bash to execute code on a Windows machine? Should I refrain from doing so?
-
So in git bash does it not print "Welcome to Calculator" until you type 2?thesecretmaster– thesecretmaster2016年12月23日 01:43:20 +00:00Commented Dec 23, 2016 at 1:43
-
Yes. If I include any more 'gets' it waits for me to type them all in to display the 'puts'Bendzukic– Bendzukic2016年12月23日 02:42:01 +00:00Commented Dec 23, 2016 at 2:42
-
Seems like @kbyte has a good answer to me. I can't think of any other reason.thesecretmaster– thesecretmaster2016年12月23日 02:52:12 +00:00Commented Dec 23, 2016 at 2:52
-
Confirmation: ruby-forum.com/topic/208856thesecretmaster– thesecretmaster2016年12月23日 02:54:31 +00:00Commented Dec 23, 2016 at 2:54
1 Answer 1
Take a look here:
Cmd and Git bash have a different result when run a Python code
The windows terminal uses strange buffered streams. Try to force the flush like the python example.
Comments
Explore related questions
See similar questions with these tags.