# How to quote special characters in run() function

**URL:** <https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359>\
**Category:** General Usage\
**Created:** [March 1, 2019, 5:19pm UTC](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359 "2019-03-01T17:19:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 1, 2019, 5:19pm UTC](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359/1 "2019-03-01T17:19:17Z")

</div>

Hi,  
I try to execute a shell command with Julia 1.1 on linux with the run() function.

```julia
julia> a
"f1.txt"

julia> b
"f2.txt"

julia> run(`cat $a >> $b`)
ERROR: failed process: Process(`cat f1.txt '>>' f2.txt`, ProcessExited(1)) [1]

julia> run(`cat $a \>\> $b`)
ERROR: failed process: Process(`cat f1.txt '>>' f2.txt`, ProcessExited(1)) [1]

```

How do I need to write \>\> to be recognized by the run() function ? Thanks !

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 1, 2019, 5:26pm UTC](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359/2 "2019-03-01T17:26:16Z")

</div>

`run(pipeline(`cat $a`, b))`

Edit: Above is wrong

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [March 1, 2019, 5:36pm UTC](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359/3 "2019-03-01T17:36:56Z")

</div>

For redirect, use the above. For append, there’s this:

```julia
open(io -> run(pipeline(`cat $a`, stdout=io)), b, "a")

```

But perhaps you can do better?

---

<div class="post-metadata">

**Author:** ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)\
**Post date:** [March 1, 2019, 7:08pm UTC](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359/4 "2019-03-01T19:08:03Z")

</div>

Thank you @kristoffer.carlsson, @bennedich

> [@kristoffer.carlsson](#):
>
> run(pipeline(`cat $a`, b))

This is equivalent to cat a \> b

> [@bennedich](#):
>
> open(io -\> run(pipeline(`cat $a`, stdout=io)), b, “a”)

This does exactly cat a \>\> b but it is very complex 🤔 run() command in Julia is much more difficult to use than system() in Perl.

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [August 12, 2020, 12:09pm UTC](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359/5 "2020-08-12T12:09:04Z")

</div>

Thank you for suggestion of using `pipeline` function to escape `>>`.  
**However, problem persists if trying to use `.` or `*` in main command, e.g: `attrib –r folder*.* /s`**

Having done some research:

- 
  1. As per [Can't run local command on Windows - #4 by pfack](https://discourse.julialang.org/t/cant-run-local-command-on-windows/2731/4), have also tried: `run(`powershell -Command "<command>"`) `, for error again.

- 
  1. Seems like if special chars are arguments of command, Julia’s inbuilt escaping will take care of issue. E.g: inbuilt `shell_escape` function.  
But if is part of main command (first parameter), escaping is not possible.

- 
  1. So even if wrapping `.` and `*` in quotation marks to snooze Julia REPL error, Windows PowerShell will complain about received input.
