Julia shell command tar and pigz pipeline

I want to compress a folder in julia:

tar -cvf - "source" | pigz -k -9 > "source.tar.xz"

where source is a folder

I tried this in julia:

run(pipeline(`tar -cvf - "2001_ A Space Odyssey"` , `pigz -k -9 \> "2001_ A Space Odyssey.tar.xz"`))

but it didn’t work. I got error below:

pigz: skipping: > does not exist
pigz: skipping: 2001_ A Space Odyssey.tar.xz does not exist
2001_ A Space Odyssey/
2001_ A Space Odyssey/cover.jpg
ERROR: LoadError: failed process: Process(`pigz -k -9 '>' '2001_ A Space Odyssey.tar.xz'`, ProcessExited(1)) [1]

How can I do it in julia?

just like pipeline for |, you can’t use > because that’s also part of the shell and Julia is not sending these through the shell.

One hack you can do is prepend whatever you want to send to shell with sh -c and quote the remaining, that way you will be using your actual shell for >

1 Like

With pipeline the equivalent of shell_command > destination_file is to give the destination filename as last argument:

dir = "2001_ A Space Odyssey"
run(pipeline(`tar -cvf - $dir` , `pigz -k -9`, "$dir.tar.xz"))