0

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?

asked Dec 23, 2016 at 1:29
4
  • So in git bash does it not print "Welcome to Calculator" until you type 2? Commented 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' Commented Dec 23, 2016 at 2:42
  • Seems like @kbyte has a good answer to me. I can't think of any other reason. Commented Dec 23, 2016 at 2:52
  • Confirmation: ruby-forum.com/topic/208856 Commented Dec 23, 2016 at 2:54

1 Answer 1

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.

answered Dec 23, 2016 at 1:45
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.