# Quoting when constructing commands problematic?

**URL:** https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023
**Category:** General Usage
**Tags:** cmd
**Created:** [January 19, 2024, 5:28pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023 "2024-01-19T17:28:30Z")
**Posts on this page:** 7
**Page:** 1

<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: [January 19, 2024, 5:28pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/1 "2024-01-19T17:28:30Z")

</div>

I think the construction of commands objects on Windows uses improper quoting for directories. See [PlotlyJS causes errors, can't figure out how to use PlotlyLight - how to use Plotly from Julia? - #27 by PetrKryslUCSD](https://discourse.julialang.org/t/plotlyjs-causes-errors-cant-figure-out-how-to-use-plotlylight-how-to-use-plotly-from-julia/108853/27)

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [January 19, 2024, 5:37pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/2 "2024-01-19T17:37:48Z")

</div>

It’s really not clear what you think is broken. Can you elaborate? MWE?

---

<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: [January 19, 2024, 5:39pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/3 "2024-01-19T17:39:55Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/d/4/d413e82e861a7c038441149e4564b07c2a5675ff.png)  
The command to change the folder doesn’t work, even though the folder it does exist, because the quote needs to be `cd "hey and"`, not `cd 'hey and'`.

---

<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: [January 19, 2024, 5:59pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/4 "2024-01-19T17:59:02Z")

</div>

Apostrophe quoting in cmd is a problem:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/7/77a6d0891ac3b2a5041ce9354b1097f675c54858.png)  
Note that running commands in cmd seems to be the default for Julias on Windows systems.  
Apostrophe quoting in Powershell works fine:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/1/91728129dff5f49a29799328d498f638d0edfe7c.png)

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [January 19, 2024, 6:09pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/5 "2024-01-19T18:09:29Z")

</div>

Actually that’s nothing to do with quoting, and simply because `cd` is not actually an executable. Here I get the same error with `cd temp` even though `temp` does exist.

```julia-repl
julia> run(`cd`)
ERROR: IOError: could not spawn `cd`: no such file or directory (ENOENT)

julia> run(`cd temp`)
ERROR: IOError: could not spawn `cd temp`: no such file or directory (ENOENT)

```

`cd` is actually a builtin function to most shells, so can only be executed from a shell (such as bash or powershell), and Julia is not a shell.

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [January 19, 2024, 6:30pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/6 "2024-01-19T18:30:03Z")

</div>

> [@PetrKryslUCSD](#):
>
> Note that running commands in cmd seems to be the default for Julias on Windows systems.

No, using `run` does not launch any shell, cmd or otherwise. It executes the given command directly. For example `run(`cd 'foo bar'`)` finds an executable called `cd` and executes it with the single argument `foo bar`.

The quoting you use when entering a command in Julia is intentionally similar to how you quote things in shells, but no shell is actually ever used. The quoting is forgotten and the command is internally represented as a vector of strings such as `["cd", "foo bar"]` because this is all you need if you don’t use a shell.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 19, 2024, 8:41pm UTC](https://discourse.julialang.org/t/quoting-when-constructing-commands-problematic/109023/8 "2024-01-19T20:41:30Z")

</div>

For Julia on Windows this works:

```julia
cmd = """cd "hey and"; ls > test.txt"""
run(`powershell -command $cmd`)

```
