Getting user input like with Java's Scanner

Hi guys, this is my first post with a super-newbie question I’d like to ask:
As you may have noticed, I’m new to Julia and I have been coding with Java for a year.
I’d like to get user-input just like in Java but I’m struggling with it.

I’ve tried to use the readline() function: it works great on files, works great on REPL only too, but inside Juno is quite messy
Here is an example inside Juno:

name = readline()
println(name)

This is what I get on console as a result:

julia> asdf


julia> ERROR: UndefVarError: asdf not defined

However, if I do everything on REPL directly, it works fine:

julia> name = readline()
asdf
"asdf"

julia> print(name)
asdf
julia> 

What can I do to fix this?
I’m sorry if I got something wrong while writing this post… I do not use blogs very often.
Thanks!

For me it is not quite clear, what exactly you mean with “inside Juno”.
What do you do to run the two code lines “inside” Juno?

BTW, Welcome to Julia and this fine community!

Checked now with a new file, put some julia code into it, and used the “Run all” icon on the left side. Doesn’t work very well, even with no user input it doesn’t run the commands reliable. With user input it seems just to be worse than without.
Same with context menu “Juno” → “Run Block”.

Issue confirmed.

Hi! Thanks for the fast answer.
I tried to take a screenshot of what’s happening, hoping it’s clearer than what I wrote. I’m sorry for that

Yes, see my second post above.

I tried now with VisualCode and it seems to be the same or similar problem.
I guess it is difficult to properly route the STDIN and STDOUT streams through whatever is done by Juno/Atom or VisualCode.

You could run your file in a shell/terminal from Juno with e.g.

C:\Users\YOUR_NAME\AppData\Local\Julia-1.3.1\bin\julia.exe .\test.jl

(Windows here, you may have another path)

This works with your small example.

That’s a Juno bug that’s mostly fixed with the latest release (Juno 0.12). There’s still a problem with the first line not being printed properly though. Will try to get that fixed today.

Peek 2020-02-21 11-10

1 Like

First, thank for all the replies!
Second, in order:

You could run your file in a shell/terminal from Juno with e.g.
C:\Users\YOUR_NAME\AppData\Local\Julia-1.3.1\bin\julia.exe .\test.jl

I’m on windows too and I downloaded Julia + juno/atom from the JuliaPro 1.3.1-1 installer from the official website.
Weird thing is that this kind of installation is spread quite everywhere:

  • JuliaPro-1.3.1-1 folder in C:\
  • julia folder in C:\Users. This is even more hilarious because at some point I’ve found the folder “padding_some_junk_value” and other creative stuff
  • JuliaPro_Juno_1.3.1-1, .julia, .juliarPro folders in C:\Users\Lorenzo\

Moral of the story, I could’t find what you suggested with the path provided…

I tried this one too:

With atom/juno provided on JuliaPro 1.31-1 doesn’t work.
I really don’t know what I’m missing…

As I said, that’s the newest Juno release. JuliaPro is usually a bit behind to provide a more stable experience.

Just searching for a “julia.exe” may bring up the proper path to yours.
Tried it here, used Windows Explorer, selected C:\, entered julia.exe in the search field, waited quite a while (~2min) and my (multiple) pathes to a julia.exe came up.

In general: Julia is a young language (still), the integrated developing environment(s) (IDEs) are still younger, compared to other worlds like python or R. This fact requires some patience and personal initiative from us users and developers to work around some of the still existing issues. But be assured it will be rewarded! (just saying in case you are already loosing some patience).

Right, regarding the location of the julia binary in JuliaPro: ...\JuliaPro-1.2.0-1_build-236\Julia-1.2.0\bin\julia.exe (adapted for the version of Julia you’re running, of course) shoud be what you’re looking for, where ... is the directory you installed JuliaPro into.

Hi! Here I am again with some “news”… I really hope I don’t bother you too much.
Since JuliaPro is some versions behind for stability and I couldn’t upgrade to the just released latest version of Juno, I uninstalled everything successfully, and installed the whole thing again following these instructions:
http://docs.junolab.org/latest/man/installation/
Now I’m running files with the “include(“filepath”)” function on REPL and everything goes fine, even the readline() function now seems flawless. Thanks again pfitzseb.
However, I’ve found a problem the “Run all” button in Juno, in particular, with these combination of commands, it happens the following:

  • “run all”: “julia>” disappears from REPL
  • “Stop julia” works as expected
  • “Enter” to start Julia again will lead into this
    image

However, now I’m happy since I know how to make the stuff work, but I thought It was worth noticing that there is a weird behaviour behind the “run all” button.
Thanks again!

1 Like

Thanks for reporting back.

Atom crashing when starting a new Julia session is a windows-only issue, so I hadn’t really noticed it so far. Will try to fix asap.

1 Like