我的代码:
df = read(`df -h|grep /dev/sda1 && df -h|grep pCloud`, String)
当我运行它时,我从Julia那里得到了以下消息:
Warning: special characters "#{}()[]<>|&*?~;" should now be quoted in commands
│ caller = #shell_parse#333(::String, ::Function, ::String, ::Bool) at shell.jl:100
└ @ Base ./shell.jl:100
df: invalid option -- '|'
Try 'df --help' for more information.
ERROR: LoadError: failed
process: Process(`df '-h|grep' /dev/sda1 '&&' df '-h|grep' pCloud`, ProcessExited(1)) [1]
我发现有人有类似的problem,但他们似乎已经解决了这个问题,而不是逃脱。
发布于 2020-06-11 00:31:08
Julia命令不能在shell中运行,因此使用那样的shell特性将不起作用。如果希望通过管道从一个命令转到另一个命令,则应使用pipeline
函数;如果希望测试命令或管道的成功或失败,请使用success
函数运行它。在这种情况下,您可以这样做:
success(pipeline(`df -h`, `grep /dev/sda1`)) &&
success(pipeline(`df -h`, `grep pCloud `))
当然,在这种情况下,您可以调用df -h
一次并执行
df = read(`df -h`, String)
contains(df, "/dev/sda1") && contains(df, "pCloud")
https://stackoverflow.com/questions/62312599
复制相似问题