Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get java to output to a log when run from a batch?

I have a java file called "Ares.jar" that runs every 5 minutes via windows scheduled tasks, the batch calls:

java -jar Ares.jar >> Ares.log  

I'm not seeing any error output, is there some way to make the errors (system.err.println / exception.printStackTrace(); )go to a file?

Thanks.

like image 477
A_Elric Avatar asked Feb 06 '13 14:02

A_Elric


People also ask

How do I write the output of a batch file?

Output: The > operator is used to overwrite any file that already exists with new content. The >> operator is used to append to the text file (add to), instead of overwriting it.

How do I run a Java program using a .bat file in Windows?

1)open a notpad 2)copy and past this code and save this file as ex: test. bat 3)Double Click tha batch file. 4)put your java codes into the notepad and save it as N.B.:- save this java file same folder that your batch file exists. what's the purpose of opening up notepad when you just want to compile and run?

How do you append the output of a command to a file in Windows?

If you want to save the output from multiple commands to a single file, use the >> operator instead. This appends the output of a command to the end of the specified file, if it already exists. If the file doesn't exist, it creates a new one.


1 Answers

java -jar Ares.jar > Ares.log 2>&1 

The second part of this command will redirect stderr to stdout, ensuring that both appear in the same file.

If you want regular logs and error logs in separate files, just use:

java -jar Ares.jar > Ares.log 2>Ares.error.log

You can get the full details of everything that is possible in the documentation, available from Microsoft: http://technet.microsoft.com/en-us/library/bb490982.aspx

like image 91
JohnnyO Avatar answered Oct 03 '22 17:10

JohnnyO