`read(stdin, Char)` in REPL vs script

I have a .jl file with one line script:

i = read(stdin, Char)

If I run it, and type ab in the REPL (without pressing the return key), I get:

a'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)

julia> i
'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)

i takes the second character entered (b).

Here is the behavior in REPL (need to press the return key after typing ab)

julia> i = read(stdin, Char)
ab
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)

julia> b
ERROR: UndefVarError: `b` not defined

julia> i
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)

i takes the first character entered (a).

So read is reading different values depending on whether it is run in a script vs in REPL, and it sometimes requires pressing the return key while other times it doesn’t.

How do I make sense of this?

1 Like

How are you running the script in the REPL? include?

1 Like

I’m hitting the play button on VScode.

If I use include, I get the same behavior as entering the line directly in the REPL.

Wonder if this stems from the same problem as this: Inline evaluation: readline() is broken · Issue #785 · julia-vscode/julia-vscode · GitHub

1 Like

submitted an issue read(stdin, Char) behaves differently in REPL vs when run as a script in VSCode · Issue #55692 · JuliaLang/julia · GitHub