我需要通过 Go 编程语言执行这种命令:find /some/dir/path -type f \( -iname \*.zip -o -iname \*.tar -o -iname \*.rar \)我发现了 exec.Command 并尝试了各种执行find命令的方法,例如exec.Command("find", dir, "-type", "f", "\\( -iname \\*.zip -o -iname \\*.tar -o -iname \\*.rar \\)")exec.Command("find", dir, "-type", "f", "-iname", "*.zip", "-o", "-iname", "*.tar", "-o", "-iname", "*.rar")exec.Command("find", dir, "-type", "f", "\\(", "-iname", "\\*.zip", "-o", "-iname", "\\*.tar", "-o", "-iname", "\\*.rar", "\\)")以上都不适合我。有没有办法做到这一点,还是我只需要在 Go 中发出 3 个单独的 find 命令?
1 回答
HUWWW
TA贡献1874条经验 获得超12个赞
exec.Command
不是外壳,因此您无需在命令中转义特殊字符。完全按照您希望命令处理的方式传递每个参数。
exec.Command("find", dir, "-type", "f", "(", "-iname", "*.zip", "-o", "-iname", "*.tar", "-o", "-iname", "*.rar", ")")
- 1 回答
- 0 关注
- 189 浏览
添加回答
举报
0/150
提交
取消