【问题标题】:run cqlsh shell command from golang从 golang 运行 cqlsh shell 命令
【发布时间】:2017-07-03 09:53:42
【问题描述】:

我正在尝试从 golang 运行 cqlsh shell 命令 'COPY',但它始终是退出状态 2。

cmd := "/path/to/my/cqlsh"
args := []string{`ipaddress -e "COPY keyspace.table (cl1, cl2) to /path/to/file"`}
exec.Command(cmd, args...).Run()

这总是出错。

【问题讨论】:

  • 错误是什么?您将 args 作为单个参数传递。
  • args := []string{"ipaddress", "-e", "COPY keyspace.table (cl1, cl2) to /path/to/file"} ... :1:SyntaxException: 第 1:0 行在输入 'COPY 处没有可行的替代方案....

标签: go cqlsh


【解决方案1】:

当您传入参数时,它们需要正确格式化,这意味着您不能将它们作为单个字符串一起传递。您还需要对 CQL 命令的引号进行转义,以便将整个命令视为单个命令行参数。

参数应该是这样的:

args := []string{"ipaddress", "-e", "\"COPY keyspace.table (cl1, cl2) to /path/to/file\""}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-13
    • 2011-03-03
    • 2011-06-04
    • 2015-07-17
    • 2018-07-30
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多