# Can't run local command on Windows

**URL:** <https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731>\
**Category:** General Usage\
**Created:** [March 17, 2017, 3:39pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731 "2017-03-17T15:39:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfack](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@pfack](https://discourse.julialang.org/u/pfack)\
**Post date:** [March 17, 2017, 3:39pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/1 "2017-03-17T15:39:54Z")

</div>

Something in the PATH works (e.g.):

```julia
run(`git submodule update --init --recursive $smName`)

```

where smName is a string defined previously.

But, when I want to run a script in a directory, something like

```julia
run(`./bootstrap`)

```

or

```julia
run(`.\\bootstrap`)

```

where either one of those works calling it in a cmd or powershell window. I get

```julia
ERROR: LoadError: could not spawn `./bootstrap`: no such file or directory (ENOENT)

```

or (respectively)

```julia
ERROR: LoadError: could not spawn `'.\bootstrap'`: no such file or directory (ENOENT)

```

The latter error presents another problem (because quoting the command won’t run the command). It still shouldn’t fail, however, because running that single-quoted string in powershell returns the quoted string back to you:

```julia
> '.\bootstrap'
.\bootstrap

```

So, what am I doing wrong here? FYI, it works perfectly on linux.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [March 17, 2017, 8:16pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/2 "2017-03-17T20:16:33Z")

</div>

Is `bootstrap` a windows batch file? (`.bat` or .`cmd`)  
Then try with the file extension.  
`run(`bootstrap.cmd`)`

---

<div class="post-metadata">

**Author:** ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)\
**Post date:** [March 17, 2017, 9:32pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/3 "2017-03-17T21:32:55Z")

</div>

libuv is not capable of spawning batch files directly.

The quoting of commands in printing isn’t done in a way that is appropriate for windows cmd. That could be fixed, though cmd’s quoting rules are very complicated and it may be better to avoid it entirely.

---

<div class="post-metadata">

**Author:** ![pfack](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@pfack](https://discourse.julialang.org/u/pfack)\
**Post date:** [March 21, 2017, 1:23pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/4 "2017-03-21T13:23:37Z")

</div>

@greg_plowman: That one in particular is, but I need to be able to run local .exe programs as well. So, I need a general solution.

@tkelman: Is there a way to manually specify using powershell or git bash even, instead of cmd?

---

<div class="post-metadata">

**Author:** ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)\
**Post date:** [March 21, 2017, 1:34pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/5 "2017-03-21T13:34:07Z")

</div>

something like

```julia
run(`powershell -Command "./bootstrap"`)

```

should work

---

<div class="post-metadata">

**Author:** ![pfack](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@pfack](https://discourse.julialang.org/u/pfack)\
**Post date:** [March 21, 2017, 3:58pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/6 "2017-03-21T15:58:46Z")

</div>

@tkelman: Thanks. That works fine.

On the other hand, if people want to treat Julia as a scripting language, the Cmd functions should work cross-platform without extra code. Julia should make jump through this kind of hoop instead of the programmer. I know that’s probably asking a lot (I’ve seen a little of the discussion around this on the issue tracker), but from a user’s perspective, that’s basic scripting functionality.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [March 21, 2017, 10:34pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/7 "2017-03-21T22:34:52Z")

</div>

> [@pfack](#):
>
> That one in particular is, but I need to be able to run local .exe programs as well. So, I need a general solution.

If it’s possible for you to always specify the extension, then it should work:

`run(`program1.exe`)`  
`run(`program2.com`)`  
`run(`script1.bat`)`  
`run(`script2.cmd`)`

---

<div class="post-metadata">

**Author:** ![pfack](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@pfack](https://discourse.julialang.org/u/pfack)\
**Post date:** [March 22, 2017, 1:13pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/8 "2017-03-22T13:13:11Z")

</div>

@greg_plowman: That doesn’t work on linux, though. You have to give the “./”

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [March 22, 2017, 9:18pm UTC](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/9 "2017-03-22T21:18:37Z")

</div>

OK, seems like you want something to work for Windows and Linux (without using `if is_windows()` or similar).  
Not sure if this is currently possible since Windows will require file extensions for `.bat` and `.cmd` files, and these are unlikely to be names on Linux.

Note that `run(`.\\program.[exe|com|bat|cmd]`)` will work on Windows.

Also if you already have a string `cmdname` appropriate for the OS, then the following should work for both Windows and Linux:

```julia
cmdpath = joinpath(".", cmdname)
run(`$cmdpath`)

```
