【问题标题】:'No such file or directory' when running Makefile script运行 Makefile 脚本时“没有这样的文件或目录”
【发布时间】:2018-03-24 19:56:13
【问题描述】:

文件夹结构是这样设置的:

Main directory
  \_ keyspaces
    \_ f1
      \_ bootstrap.cql
      \_ anotherFolder
        \_ 0001-something.cql
    \_ f2
      \_ bootstrap.cql
      \_ anotherFolder
        \_ 0001-something.cql
        \_ 0002-moreSomething.cql

我在主目录中有一个包含此代码的 Makefile:

do_stuff:
    for ks in keyspaces/*; do \
        cqlsh -f "$${ks}/bootstrap.cql"; \
    done

当我从主目录内的终端(使用 iTerm2)运行 make do_stuff 时,出现错误,说明如下:

Can't open 'keyspaces/f1/bootstrap.cql': [Errno 2] No such file or directory: 'keyspaces/f1/bootstrap.cql'
command terminated with exit code 1
Can't open 'keyspaces/f2/bootstrap.cql': [Errno 2] No such file or directory: 'keyspaces/f2/bootstrap.cql'
command terminated with exit code 1
make: *** [do_stuff] Error 1

但是,如果我在终端中运行此程序:cat keyspaces/f1/bootstrap.sql 我会打印出该文件的内容,因此路径正确且确实存在,但 cqlsh 无法识别它?

查看the Cassandra/cqlsh docs,看起来我正在正确使用-f 命令,所以我不知道为什么会出现错误。

【问题讨论】:

  • cat keyspaces/f1/bootstrap.cql 怎么样?

标签: makefile cassandra cql cqlsh iterm2


【解决方案1】:

我会从消除潜在问题的简单步骤开始

.
├── Makefile
└── keyspaces
    ├── f1
    │   └── bootstrap.cql
    └── f2
        └── bootstrap.cql

使用以下 Makefile,可以正常工作

do_stuff:
    for ks in keyspaces/*; do \
        cat "$${ks}/bootstrap.cql"; \
    done

执行

make
for ks in keyspaces/*; do \
      cat "${ks}/bootstrap.cql"; \
    done
a
b

仔细检查,您可以在Main directory 内调用

cqlsh -f "keyspaces/f1/bootstrap.cql"

也许您可以将此委托给find?

do_stuff:
    find `pwd` -name "*.cql" -exec cat {} \;

【讨论】:

  • cat 的第一个循环工作正常,但是,您建议在 Main directory 内运行的最后一行代码会引发未找到的错误,因此该 Cassandra 一定有问题我正在尝试运行的命令:/如果我弄清楚了,我会发布更新。谢谢!
  • 再问一个问题,也许你可以简单地使用 find 而不是 makefile?查找pwd -name "*.cql" -exec cqlsh -f {} \;
  • 它似乎有效,但是当我在循环中使用它时,我得到find: -exec: no terminating ";" or "+"
  • 您的解决方案实际上也很有效(5 分钟后我无法编辑之前的评论)。但是,我可能会打开一个新的更具体的问题来弄清楚为什么我仍然无法使用 cqlsh 使用 -f 选项运行 .cql 文件,即 cqlsh -f 'somefile.cql'
猜你喜欢
  • 2016-01-10
  • 1970-01-01
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
  • 2016-08-15
  • 2017-07-07
  • 2014-05-09
  • 1970-01-01
相关资源
最近更新 更多