7

Is it possible to save the output of a bazel build command that is run in terminal? The command is:

bazel build tensorflow/examples/image_retraining:label_image && 
bazel-bin/tensorflow/examples/image_retraining/label_image 
--graph=/tmp/output_graph.pb 
--labels=/tmp/output_labels.txt 
--output_layer=final_result:0 
--image=$HOME/Desktop/Image-3/image1.png

I want to save the output to a .txt file; I cannot simply tag on > out.txt to the end of the line or I am thrown an error. But is there bazel-output command?

2 Answers2

5

The stdout of the latest bazel command is logged in your WORKSPACE's output base:

$ echo $(bazel info output_base)
/home/username/.cache/bazel/_bazel_username/3e8af127f8b488324cdf41111355ff4c

and the exact file is command_log:

$ echo $(bazel info command_log)
/home/username/.cache/bazel/_bazel_username/3e8af127f8b488324cdf41111355ff4c/command.log
Jin
  • 12,748
  • 3
  • 36
  • 41
  • 2
    The command_log truncates to the last INFO line. Everything after that is lost. – Rohan Pandya Mar 19 '19 at 23:28
  • @jin are you sure? Just tried it and found only the name of the same file in it – Ittai Oct 06 '19 at 16:48
  • 1
    @Ittai yes. `bazel info command_log` itself is a bazel command, so you cannot use `echo $(bazel info command_log)` to print the contents of the *last* bazel invocation. You have to use the exact path. – Jin Oct 06 '19 at 21:12
  • This file is also accessible via something like this, assuming you're in your git repo's root dir: `build/bin/../../../../../command.log`. – Gabriel Staples Sep 30 '20 at 23:12
2

You can do it by piping the output to both text file and command line, but only on linux. You just append this at the end 2>&1 | tee file_name.log

J. Bajic
  • 56
  • 6