I’m encountering a strange behavior when running Julia through VSCode, and I’m hoping someone can help me understand and resolve it.
Consider the following function:
function test()
@show Base.stdin
x = readline()
@show x
return nothing
end
When I run this function directly in the Julia REPL, I get the expected behavior: the stdin
variable is shown, I type a message, and the message gets shown back to me:
julia> test()
Base.stdin = Base.TTY(RawFD(12) paused, 0 bytes waiting)
msg1
x = "msg1"
However, when I run this function through VSCode (by hitting Ctrl + Enter in the editor), I get different and unexpected behavior:
Base.stdin = Base.TTY(RawFD(12) active, 0 bytes waiting)
julia> msg1
msg2
x = "msg2"
julia> ERROR: UndefVarError: `msg1` not defined
First, we observe that the stdin
is active instead of paused. Then, I try to type msg1
once again. When I hit Enter, a julia>
prompt appears on the new line, but the function does not proceed. I then type msg2
, which finally gets picked up by the function. In the end, I get an error, which is consistent with typing msg1
directly into the REPL.
Does anyone know what is going on here, and if there is a fix?
I have seen this happening in both a Windows and a Linux machine. I also get the expected behaviour when using the REPL inside VSCode. The problem only appears when running the code from the editor.