1

I am trying to pick up Julia and I wanted to program a tiny game where the user would guess a random number from [0-9]. But, user input does not work for me and I don't understand why.

I am on Windows 10, Visual Studio 1.37.1 (with Julia extension), Julia 1.2.0.

I have tried to get user input on the REPL, no problem.

Now if I put the exact same code in a script and julia < my_script.jl, it does not work. The script runs, but it does not let me write anything.

x = readline(); println(x)

This is the code that works in REPL, but not in script

I expect the script to halt, let me enter the input then print what I have entered, but it does not stop for me to write anything and just prints an empty line.

  • You could try to use this function [here](https://stackoverflow.com/a/23342933/2374329) from a related question, I could not reproduce the issue you describe. Try with `println("type something now: "); x = readline(); println(x)` this way the program prompts you for input and it's easier to see when it's ready for your input, or try with the linked function `println(input("type something now: "))`. – HarmonicaMuse Sep 05 '19 at 15:54

1 Answers1

2

In the terminal (or at the command prompt for Windows), type julia my_script.jl instead of julia < my_script.jl.

Cameron Bieganek
  • 7,208
  • 1
  • 23
  • 40