Why does the ">" command in a Windows console not redirect all messages to a file?
I am trying to build a Scala project with sbt, so I run a command:
sbt clean test > log.log
Which means that any messages that the sbt tool writes to the Windows console should be written to the "log.log" file. But sometimes I get stacktrace written to the console and not into the file:
C:\path>sbt clean test > log.log
java.lang.ExceptionInInitializerError
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.ClassCastException: Class org.infinispan.configuration.parsing.Parser60 does not implement org.infinispan.configuration.parsing.ConfigurationParser
Why does ">" command not redirect all messages to a file?
Solution 1:
What you have pasted is not command standard output (STDOUT), but error output of the command (STDERR).
When you add "> output_file" to command, you are only redirecting STDOUT to that file, not STDERR.
If you want to output errors, to the same file as standard output you need to use
sbt clean test > log.log 2>&1
what "2>&1" does, is, it says to output error to same place as standard output results.
You can also do something like this:
sbt clean test > log.log 2>error.log
It will output STDOUT to log.log, and STDERR to second file called error.log, if you want to separate them.
See this about command redirector operators
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true