How do I get the commands executed by Bazel answers a similar question for bazel build
, and --subcommands
works well for that. But --subcommands
does not show the command that's executed for bazel run
.
1 Answers
It's just running the executable built by the target you give it, plus anything else that isn't a bazel flag. Determining what's a bazel flag follows common semantics: anything that doesn't start with -
anywhere, and anything at all after --
. Some examples:
bazel run //foo:bar
runs bar
.
bazel run --subcommands //foo:bar
and bazel run //foo:bar --subcommands
are both just running bar
. There are no flags after --
because there is no --
.
bazel run //foo:bar xyz
runs bar xyz
, because xyz
doesn't start with -
. bazel run //foo:bar -- xyz
also does the same thing
bazel run //foo:bar -- --subcommands
runs bar --subcommands
, without bazel interpreting --subcommands
.
You can also use --script_path to output a shell script with the full command and environment setup written out.

- 3,085
- 11
- 13
-
`bar` is the name of a bazel target, not the name of an executable. For example, consider `nodejs_binary(name = "bar", ...)`. `bazel run :bar` presumably runs some nodejs binary with some arguments. I want to know which binary and what arguments. (Actually it turns out that it runs a shell script, but same idea.) – John May 10 '22 at 23:52
-
`--script_path` does get me what I'm looking for though! It would be great if `bazel run --subcommands` just output what `--script_path` writes to a file. Sometimes I just have to shake my head at bazel's UX... – John May 10 '22 at 23:56
-
`--subcommands` doesn't seem to even show the subcommands. They're truncated somehow. Cannot figure out how to see what command is actually executed. – Zendel Jul 20 '22 at 01:09