20

Inspired by the examples on the SBT github page, I'm trying to redirect the stdout produced from a run in SBT's interactive mode to a file.

Here's my failed attempt:

> run #> file('/Users/dsg/temp/temp.txt') !

I've tried both with and without the ! at the end. I've tried both single and double quotes. Nothing works -- it just behaves as if the #> file(... is omitted, things only get printed to stdout, no file is created.

4 Answers 4

15

I'm not an SBT expert, but this doesn't seem to be the correct feature.

> run is interpreting everything after it as file arguments. #> seems to be part of the sbt library, for use inside of your project sbt files, not at their prompt.

Getting around this, I exit sbt, and use my external shell to do this:

$ sbt "run" > run_output.txt
1
  • 1
    Despite this approach works in general, it's not really the best approach in certain corner cases. I have a use case involving Scala scripts which, in a nutshell implies that the output of the Scala script gets mixed with output from SBT... resulting in a big mess which cannot be processed by the next step in the pipeline. Ideally, we should be able to tell SBT to write stdout to stderr, for example. This way, output from Scala scripts would not be mixed by informational messages and error messages coming from SBT. Commented Jun 24, 2016 at 9:18
7

This worked for me:

sbt | tee log.txt
1
  • Changes the prompt from regular sbt shell to >.... ignoring that logging works perfect Commented Feb 23 at 20:03
4

Don't know how to do it from the sbt console, but from shell command line you can capture the sbt output via:

sbt "test" 2>&1 > test.log
1

You could try this.

sbt test >> "log.txt"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.