How to quote special characters in run() function

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 !

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

Edit: Above is wrong

2 Likes

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

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.

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, 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.
2 Likes