# Better support for running external commands

**URL:** <https://discourse.julialang.org/t/better-support-for-running-external-commands/44933>\
**Category:** New to Julia\
**Tags:** run, cmd\
**Created:** [August 14, 2020, 2:18pm UTC](https://discourse.julialang.org/t/better-support-for-running-external-commands/44933 "2020-08-14T14:18:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [August 14, 2020, 3:01pm UTC](https://discourse.julialang.org/t/better-support-for-running-external-commands/44933/2 "2020-08-14T15:01:17Z")

</div>

> [@Amin\_Yahyaabadi](#):
>
> You can’t run external commands with special characters.

You can do this by quoting the command with single or double backticks.

> [@Amin\_Yahyaabadi](#):
>
> using `Cmd` direcrtly fails
> 
> ```julia
> julia
> 
> ```

This is because globs (e.g. `*` to match any string) don’t work in Julia (yet).

> [@Amin\_Yahyaabadi](#):
>
> ```julia
> # this works
> julia> run(`echo hey/\*`)
> hey/*
> Process(`echo 'hey/*'`, ProcessExited(0))
> 
> ```

This only matches a path with the literal name `*`, which is probably not what you want.

> [@Amin\_Yahyaabadi](#):
>
> ```julia
> # this doesn't
> julia> run(`echo hi \&\& echo bye`) # or run(`echo hi '&&' echo bye`)
> hi && echo bye
> Process(`echo hi '&&' echo bye`, ProcessExited(0))
> 
> ```

It does what you ask it to, it escapes `&&` as an argument to echo. `&&` for command chaining, like in bash, is also not currently supported.

> [@Amin\_Yahyaabadi](#):
>
> 1. Possibility of using `String` for building a command
> 
> ```julia
> julia> x = "echo bye"
> "echo bye"
> 
> ```

This is actually a feature, because it protects you from command injection. You usually don’t just want to run arbitrary strings as commands. If you really want to create a command from a string like this, you need to call `Base.shell_parse` directly, but this could definitely be documented better.

I do agree that there are still a lot of ways running external commands could be improved. To me, that would mean moving [Glob.jl](https://github.com/vtjnash/Glob.jl) into base, supporting piping and chaining constructs like `|`, `>`, `&&`, etc. directly in command literals, and I’d also really like to see [parse command interpolations at parse time · Issue #3150 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/3150) being addressed.

---

_[View the full topic](https://discourse.julialang.org/t/better-support-for-running-external-commands/44933)._
