# Command from a string

**URL:** <https://discourse.julialang.org/t/command-from-a-string/85237>\
**Category:** New to Julia\
**Created:** [August 3, 2022, 3:15pm UTC](https://discourse.julialang.org/t/command-from-a-string/85237 "2022-08-03T15:15:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![whatsthecraic](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@whatsthecraic](https://discourse.julialang.org/u/whatsthecraic)\
**Post date:** [August 3, 2022, 3:15pm UTC](https://discourse.julialang.org/t/command-from-a-string/85237/1 "2022-08-03T15:15:42Z")

</div>

Hi there, how can I create & run a command from a string, e.g.

```julia
julia> str = "echo hello world"
"echo hello world"

julia> read(`$(str)`)
ERROR: IOError: could not spawn `'echo hello world'`: no such file or directory (ENOENT)

```

(assume str is a complex command and I’d like to perform my own escaping of arguments)

Thanks

---

<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:** [August 3, 2022, 4:15pm UTC](https://discourse.julialang.org/t/command-from-a-string/85237/2 "2022-08-03T16:15:36Z")

</div>

> [@whatsthecraic](#):
>
> (assume str is a complex command and I’d like to perform my own escaping of arguments)

Sounds like you are thinking of a shell command? To do that you want to spawn a shell:

```julia
julia> run(`sh -c $str`);
hello world

```

This is the analogue of the `os.system` function in Python or the `system` function in C.

Of course, the whole reason why Julia’s `run` commands are set up the way they are is [to _avoid_ spawning a shell and to avoid brittle manual escaping](https://julialang.org/blog/2012/03/shelling-out-sucks/). See also this discussion: [Better support for running external commands - #8 by stevengj](https://discourse.julialang.org/t/better-support-for-running-external-commands/44933/8)

Could you give more context about why you are doing this?
