How to quote special characters in run() function

#1

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

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 !

#2

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

Edit: Above is wrong

2 Likes
#3

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

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

But perhaps you can do better?

1 Like
#4

Thank you @kristoffer.carlsson, @bennedich

This is equivalent to cat a > b

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