# Strange difference between running readline in REPL or VSCode

**URL:** <https://discourse.julialang.org/t/strange-difference-between-running-readline-in-repl-or-vscode/117381>\
**Category:** General Usage\
**Tags:** vscode\
**Created:** [July 23, 2024, 11:14am UTC](https://discourse.julialang.org/t/strange-difference-between-running-readline-in-repl-or-vscode/117381 "2024-07-23T11:14:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcsgil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcsgil/32/33908_2.png) [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Post date:** [July 23, 2024, 11:14am UTC](https://discourse.julialang.org/t/strange-difference-between-running-readline-in-repl-or-vscode/117381/1 "2024-07-23T11:14:37Z")

</div>

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:

```julia
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
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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [July 23, 2024, 11:27am UTC](https://discourse.julialang.org/t/strange-difference-between-running-readline-in-repl-or-vscode/117381/2 "2024-07-23T11:27:42Z")

</div>

This is

> <https://github.com/julia-vscode/julia-vscode/issues/785>
>
> There seems to be an issue with the new terminal communication and reading stdin…. Executing the file
> \`\`\`julia
> for n in 1:5
> println(n)
> readline()
> end
> \`\`\`
> through vscode will drop back to the REPL prompt after the first iteration. Loading the same file with include() works as expected.
> 
> Version: 0.12.0-beta.2
> OS: Windows 10
