Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to capture javac output in bash shell

Tags:

bash

shell

javac

I'm trying to redirect the java compiler output to a file. I thought it's supposed to be:

javac file.java > log.txt

or something. Instead, I see all the output on the terminal and nothing in log.txt!

Also, if I want to log errors too, do I do

javac file.java 2>&1 > log.txt

?

like image 962
jcee14 Avatar asked Nov 25 '08 15:11

jcee14


2 Answers

javac file.java 2> log.txt

The reason is that you have two output file descriptors instead of one. The usual one is stdout, which you can redirect with > and it's supposed to be used for resulting output. The second one, stderr, is meant for human readable output like warnings, errors, current status etc., this one is redirected with 2>.

Your second line, using 2>&1, redirects stderr to stdout and finally stdout into log.txt.

like image 135
Julien Oster Avatar answered Nov 08 '22 01:11

Julien Oster


Have you tried

javac -Xstdout log.txt file.java

This will send compiler errors to a log file instead of stderr.

like image 7
Bill the Lizard Avatar answered Nov 08 '22 01:11

Bill the Lizard