# Fail to run shell command

**URL:** https://discourse.julialang.org/t/fail-to-run-shell-command/55543
**Category:** New to Julia
**Created:** [February 18, 2021, 2:42pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543 "2021-02-18T14:42:16Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)
#### Post date: [February 18, 2021, 2:42pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/1 "2021-02-18T14:42:16Z")

</div>

Hei,

In Julia 1.4, in Atom-IDE’s REPL, Windows, Julia and I have the following dialog

```julia
julia> run(`echo hello`)
ERROR: IOError: could not spawn `echo hello`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:99
 [2] #550 at .\process.jl:112 [inlined]
 [3] setup_stdios(::Base.var"#550#551"{Cmd}, ::Array{Any,1}) at .\process.jl:196
 [4] _spawn at .\process.jl:111 [inlined]
 [5] run(::Cmd; wait::Bool) at .\process.jl:439
 [6] run(::Cmd) at .\process.jl:438
 [7] top-level scope at none:0

```

The command I type is straight from Julia’s manual, so I am baffled. Any idea?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 18, 2021, 2:50pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/2 "2021-02-18T14:50:16Z")

</div>

> [@Philippe\_Maincon1](#):
>
> The command I type is straight from Julia’s manual, so I am baffled. Any idea?

`echo` is not a program that is available in the Windows command path by default. (It’s a Unix thing.)

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [February 18, 2021, 2:50pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/3 "2021-02-18T14:50:56Z")

</div>

In Linux echo is an application. In windows it’s a feature of the cmd console. Try

```julia
run(`cmd /k echo hello`)

```

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)
#### Post date: [February 18, 2021, 2:53pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/4 "2021-02-18T14:53:41Z")

</div>

I did open a cmd prompt, and echo hello worked wonders.  
And your suggestion works. 😀  
So this means my first attempt sends a command to another shell, while yours sends a command to the same shell I opened?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 18, 2021, 2:55pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/5 "2021-02-18T14:55:09Z")

</div>

One of these days it would be nice to get reasonable shell functionality on Windows by default. We’ve been back and forth on many different possible solutions, but the simplest seems to be to ship with `busybox` and put that in the path: see [this comment](https://github.com/JuliaLang/julia/pull/33474#issuecomment-659567510) by @StefanKarpinski.

Not a lot of people want to work on it, though. Spawning command-line programs on Windows can be really awkward under the hood because [there isn’t a proper way to pass command-line arguments](https://github.com/JuliaLang/julia/issues/13776) as a list of strings, only a set of not-completely-universal parsing rules. See also [https://github.com/JuliaLang/julia/pull/33465](https://github.com/JuliaLang/julia/pull/33465) which painfully implemented this.

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)
#### Post date: [February 18, 2021, 3:01pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/6 "2021-02-18T15:01:20Z")

</div>

```julia
run(`cmd /k dir´)

```

does not work. Though

```julia
run(`cmd /k´) 

```

switches to a shell, ctrl-c to exit. …but that does not help to have Julia code generate DOS commands.

Steven, I’ll look at the winsomely thing.

Thanks, I’ll go get myself Linux… 🙂

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [February 18, 2021, 3:03pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/7 "2021-02-18T15:03:36Z")

</div>

> [@Philippe\_Maincon1](#):
>
> run(`cmd /k dir´)

That didn’t work?!?!? That should have worked. It works on my 1.5.3. 😕

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [February 18, 2021, 3:34pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/8 "2021-02-18T15:34:56Z")

</div>

> [@Philippe\_Maincon1](#):
>
> So this means my first attempt sends a command to another shell, while yours sends a command to the same shell I opened?

Not really: Julia doesn’t use a shell to run a program. It just runs the program directly.

With

```julia
run(`echo hello`)

```

you ask Julia to execute the program `echo` (Windows will look for `echo.exe`, `echo.com`, etc.) with argument `hello`. This program exists on Linux but not on Windows.

With

```julia
run(`cmd /k echo hello`)

```

you ask Julia to execute the program `cmd` with arguments `/k`, `echo` and `hello`. The program `cmd.exe` is actually a shell so that will execute a shell 🙂

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [February 18, 2021, 3:39pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/9 "2021-02-18T15:39:49Z")

</div>

Use /c instead of /k

```julia
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains

```

---

<div class="post-metadata">

### Author: ![innerlee](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@innerlee](https://discourse.julialang.org/u/innerlee)
#### Post date: [February 18, 2021, 3:49pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/10 "2021-02-18T15:49:00Z")

</div>

try Shell.jl? [GitHub - innerlee/Shell.jl: Run shell commands becomes easy in Julia!](https://github.com/innerlee/Shell.jl)

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 18, 2021, 4:30pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/11 "2021-02-18T16:30:46Z")

</div>

> [@stevengj](#):
>
> Not a lot of people want to work on it, though.

Seems like basically we’d need a PR that reverts [#30022](https://github.com/JuliaLang/julia/pull/30022) (to re-include busybox on Windows) and then adds it to the command path.

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [February 18, 2021, 4:38pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/12 "2021-02-18T16:38:16Z")

</div>

If one actually needs an echo program on Windows, I got one when installing git, `C:\Program Files\Git\usr\bin\echo.exe`.

---

<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: [February 18, 2021, 4:55pm UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/13 "2021-02-18T16:55:34Z")

</div>

> [@Using Julia on Git bash](https://discourse.julialang.org/t/using-julia-on-git-bash/24413/2):
>
> Put this into a .bat file: start "" "%PROGRAMFILES%\Git\bin\sh.exe" --login -i -c "exec julia"

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)
#### Post date: [February 19, 2021, 5:02am UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/14 "2021-02-19T05:02:11Z")

</div>

Well, `echo` was just a mnwe (minimum non working example) and not the motivation for my question. But, good to know!

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)
#### Post date: [February 19, 2021, 5:07am UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/15 "2021-02-19T05:07:27Z")

</div>

Hi Sudete, you nailed my problem: I was assuming `run` sends command to a shell, and from there, I was floored. 👍

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)
#### Post date: [February 19, 2021, 5:08am UTC](https://discourse.julialang.org/t/fail-to-run-shell-command/55543/16 "2021-02-19T05:08:20Z")

</div>

I will!
