How do I pipe Java exceptions into a text file along with normal output?

2

When I use batchfile.bat >> logfile.txt command in the Windows commandline, it correctly outputs the normal output into the text file, but the Java exceptions get output to the console. Can I make it so that exceptions are written to log file as well?

EndangeringSpecies

Posted 2009-12-27T22:06:47.633

Reputation: 593

Answers

7

Java exceptions are printed on the standard error stream.

To pipe the standard error stream (file descriptor 2) into a file you can do:

batchfile.bat 2>> errorlog.txt

To pipe both standard error and standard out into the same file:

batchfile.bat >> logfile.txt 2>&1

You can do the same on Unix and Windows

Alex Jasmin

Posted 2009-12-27T22:06:47.633

Reputation: 462