在Julia中使用特殊字符“>”运行外部程序
我想在 Julia 中运行一个包含特殊字符“>”的外部程序
gunzip -c file.nc.gz > file.nc
但我收到此错误:
ERROR: LoadError: LoadError: parsing command `gunzip -c $filein /> $fileout`:
special characters "#{}()[]<>|&*?~;" must be quoted in commands
我能解决这个问题吗?谢谢
回答
使用pipeline而不是使用 shell 语法 ( >) 进行流重定向。
例子:
shell> ls
file.txt.gz
julia> p = pipeline(`gunzip -c file.txt.gz`; stdout="file.txt");
julia> run(p);
shell> ls
file.txt file.txt.gz
shell> cat file.txt
hello, world
或者,您可以调用一个了解>含义的 shell,例如bash:
run(`/bin/bash -c "gunzip -c file.txt.gz > file.txt"`)