# Windows, Command for VS Code

**URL:** <https://discourse.julialang.org/t/windows-command-for-vs-code/29902>\
**Category:** New to Julia\
**Tags:** shell\
**Created:** [October 14, 2019, 2:34pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902 "2019-10-14T14:34:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [October 14, 2019, 2:34pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/1 "2019-10-14T14:34:30Z")

</div>

I can’t get the console to find the code executable:

```julia
C:\Users\necka>code #works as expected

C:\Users\necka>julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.3.0-rc2.0 (2019-09-12)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

shell> code
ERROR: IOError: could not spawn `code`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:99
 [2] setup_stdios(::Base.var"##558#559"{Cmd}, ::Array{Any,1}) at .\process.jl:112
 [3] _spawn at .\process.jl:111 [inlined]
 [4] #run#569(::Bool, ::typeof(run), ::Cmd) at .\process.jl:439
 [5] run at .\process.jl:438 [inlined]
 [6] repl_cmd(::Cmd, ::REPL.Terminals.TTYTerminal) at .\client.jl:77
 [7] top-level scope at none:0

```

As you can see it cannot find the executable for vscode. I need it to be able to enable @edit to open the editor with the correct line information. Right now line information is not passed even though vscode is opened.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 14, 2019, 2:48pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/2 "2019-10-14T14:48:17Z")

</div>

Have you tried the full path to code.exe?  
For me it would be:

```julia
shell> "C:\Users\Oli\AppData\Local\Programs\Microsoft VS Code\Code.exe"

 [main 2019-10-14T14:47:51.409Z] update#setState idle

```

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [October 14, 2019, 2:54pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/3 "2019-10-14T14:54:10Z")

</div>

```julia
julia> ENV["JULIA_EDITOR"]=replace(raw"C:\Users\necka\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd", "\\"=>"/")
"C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd"

julia> @edit println(5)
ERROR: IOError: could not spawn `C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd 'E:\Programme\Julia\bin\..\share\julia\base\coreio.jl'`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:99
 [2] setup_stdios(::Base.var"##558#559"{Cmd}, ::Array{Any,1}) at .\process.jl:112
 [3] _spawn at .\process.jl:111 [inlined]
 [4] #run#569(::Bool, ::typeof(run), ::Cmd) at .\process.jl:439
 [5] run at .\process.jl:438 [inlined]
 [6] edit(::String, ::Int32) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\InteractiveUtils\src\editless.jl:80
 [7] edit(::Function, ::Any) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\InteractiveUtils\src\editless.jl:102
 [8] top-level scope at REPL[17]:1

```

then I get that problem.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 14, 2019, 3:04pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/4 "2019-10-14T15:04:12Z")

</div>

How about `run(`code`)`? (Or the corresponding full-path invocation.) If I remember rightly, spawning commands from the “shell” mode on Windows has a spotty record.

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [October 14, 2019, 3:07pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/5 "2019-10-14T15:07:50Z")

</div>

Indeed works, but how do I get the @edit macro to execute that code?

```julia
julia> run(`"C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd" -g 'E:\Programme\Julia\bin\..\share\julia\base\coreio.jl:29'`)
Process(`'C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd' -g 'E:\Programme\Julia\bin\..\share\julia\base\coreio.jl:29'`, ProcessExited(0))

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 14, 2019, 3:11pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/6 "2019-10-14T15:11:03Z")

</div>

Perhaps the function? From the manual:

[`InteractiveUtils.edit`](https://docs.julialang.org/en/v1/stdlib/InteractiveUtils/index.html#InteractiveUtils.edit-Tuple%7BAbstractString,Integer%7D) — Method.

```julia
edit(path::AbstractString, line::Integer=0)

```

Edit a file or directory optionally providing a line number to edit the file at. Return to the `julia` prompt when you quit the editor. The editor can be changed by setting `JULIA_EDITOR` , `VISUAL` or `EDITOR` as an environment variable.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 14, 2019, 3:21pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/7 "2019-10-14T15:21:06Z")

</div>

You need some more escapes:

```julia
julia> ENV["JULIA_EDITOR"]=raw"C:\\Users\\Oli\\AppData\\Local\\Programs\\Microsoft\ VS\ Code\\Code.exe"

```

Now

```julia
julia> edit("test.jl")

```

open vscode for me.

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [October 15, 2019, 5:06am UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/8 "2019-10-15T05:06:31Z")

</div>

This solves it! Thanks 🙂  
Though I hate that the Windows path variable is not considered when looking up executables… Thus I have to precisely say where each executable is that I might need and cannot just depend upon the executables available (on other systems where I have no control over the place).

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 15, 2019, 1:17pm UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/9 "2019-10-15T13:17:24Z")

</div>

The following is probably the better solution:

```julia
julia> ENV["JULIA_EDITOR"]="code.cmd"

```

this works here under Windows 10 and assumes that the path to VSCode is added to the PATH environment. This is an option during installation of VSCode and there is a note that you have to restart the PC.

```julia
julia> ENV["PATH"]
"...snippped...;C:\\Users\\oheil\\AppData\\Local\\Programs\\Microsoft VS Code\\bin"

```

In this path there are two files:

```julia
code
code.cmd

```

where only `code.cmd` can be started from within julia. If you try `code` in a windows cmd shell, the extenstions .exe, .cmd and .bat are automatically tested, and as there is code.cmd, this one is executed. Looking into `code` it is a unix/linux like shell script.

> Though I hate that the Windows path variable is not considered when looking up executables… Thus I have to precisely say where each executable is that I might need and cannot just depend upon the executables available (on other systems where I have no control over the place).

So the path variable is actually considered, but my first attempt with code.exe, which is not in the `bin` folder, created the impression that it is not.  
@rapus95 can you cross check and change the solution for future solution seekers?

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [October 16, 2019, 8:51am UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/10 "2019-10-16T08:51:59Z")

</div>

Indeed that works. Thanks & nice to know!

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [October 16, 2019, 8:54am UTC](https://discourse.julialang.org/t/windows-command-for-vs-code/29902/11 "2019-10-16T08:54:49Z")

</div>

Though, at the very end the error I got is plain misleading as it states that `code` is not found rather than not being executable.
