user6863891
user6863891

Reputation:

Bazel run specify multiline command

Hello I am using bazel for my project.

I always used backslash(\) to specify long commands in Linux.

I was trying the same bazel but it didn't worked

bazel build //mypackage:query_count -- \
--input="/path/to/input.json" \
--output="/path/to/output/json"

When I remove the backslash and keep them on one line the build succeeds

bazel build //mypackage:query_count -- --input="/path/to/input.json" --output="/path/to/output/json"

Does anyone know what I am doing wrong, looking into the error it looks like bazel is treating --input="/path/to/input.json" as a seprate target?

Upvotes: 1

Views: 1410

Answers (2)

ahumesky
ahumesky

Reputation: 5006

Everything after -- is interpreted as target patterns:

https://docs.bazel.build/versions/master/command-line-reference.html

bazel [<startup options>] <command> [<args>] -- [<target patterns>]

Though as Jin says above, --input and --output are not command line flags to bazel, so it's not clear what you're trying to do (unless you're just using those as dummy placeholder names for flags).

-- behaves differently for bazel run: bazel interprets everything after -- as arguments to the binary to run, see https://docs.bazel.build/versions/master/user-manual.html#run

Upvotes: 1

Jin
Jin

Reputation: 13463

--input="/path/to/input.json" and --output="/path/to/output/json" are not flags for bazel build (to build the executable). I believe you're using them as runtime flags for the underlying executable //mypackage:query_count.

You probably want to use bazel run here:

bazel run //mypackage:query_count -- \
  --input="/path/to/input.json" \
  --output="/path/to/output/json"

Upvotes: 1

Related Questions