Shell 将两个字符串传递给Julia中的外部实用程序diff
我一直在尝试将两个字符串传递给Shell 将两个字符串传递给Julia中的外部实用程序diff,shell,julia,diff,Shell,Julia,Diff,我一直在尝试将两个字符串传递给diff命令行实用程序,以实现它在Julia中的图形并排比较功能。迄今为止,我的努力包括: s1 = "<very long multiline string 1>" s2 = "<very long multiline string 2>" # Results in LoadError: parsing command `diff -y <(echo $(s1)) <(echo $(s2
diff
命令行实用程序,以实现它在Julia中的图形并排比较功能。迄今为止,我的努力包括:
s1 = "<very long multiline string 1>"
s2 = "<very long multiline string 2>"
# Results in LoadError: parsing command `diff -y <(echo $(s1)) <(echo $(s2))`:
# special characters "#{}()[]<>|&*?~;" must be quoted in commands
attempt1 = read(`diff -y <(echo $(s1)\) <(echo $(s2))`, String)
# Results in diff: extra operand '<(echo'
attempt2 = read(`diff -y \<\(echo $(s1)\) \<\(echo $(s2)\)`, String)
# Results in diff: missing operand after '<(echo
attempt3 = read(`diff -y "<(echo $(s1)) <(echo $(s2))"`, String)
# Results in diff: missing operand after '<(echo $(s1)) <(echo $(s2))'
attempt4 = read(`diff -y '<(echo $(s1)) <(echo $(s2))'`, String)
# Results in diff: <(echo <very long multiline string 1>: Filename too long
attempt5 = read(`diff -y \<\("echo $(s1)"\) \<\("echo $(s2)"\)`, String)
但是Julia对命令字符串做了一些处理,使它们不像在bash中那样运行。那么,如何将两个字符串传递给Julia中的
diff
?是的,Julia的Cmd
与bash
不同。如果您不在Windows上,则可以使用包模拟bash
行为
结果呢
julia> println(String(take!(io)))
Humpty Dumpty sat on a wall, Humpty Dumpty sat on a wall
,
Humpty Dumpty had a great fall. Humpty Dumpty had a great f
all.
All the king's horses and all the king's men | Four-score Men and Four-sco
re more,
Couldn't put Humpty together again. | Could not make Humpty Dumpt
y where he was before.
julia> println(String(take!(io)))
Humpty Dumpty sat on a wall, Humpty Dumpty sat on a wall
,
Humpty Dumpty had a great fall. Humpty Dumpty had a great f
all.
All the king's horses and all the king's men | Four-score Men and Four-sco
re more,
Couldn't put Humpty together again. | Could not make Humpty Dumpt
y where he was before.