Redirect messages

I have this script which invoke a java program and in the program I have several System.out.println
statement to write messages to standard output, I wanna to redirect these to a log file so I did

java blah blah blah > log.txt 2>&1

but I can't see any of those messages, can anybody help? Thanks!

It should work

[/tmp]$ cat test.java
import java.io.*;

public class test
{
    public static void main (String[] args)
    {
        System.out.println ("Hello World\n");
    }

}
[/tmp]$ java test
Hello World

[/tmp]$ java test > /tmp/java.log
[/tmp]$ cat /tmp/java.log 
Hello World

[/tmp]$ 

Try this

java blah blah blah > log.txt 2>log.txt

If you are looking to do quite a bit of output within your java code to standard output I would recommend using a package such as log4j -

http://logging.apache.org/log4j/docs/index.html

Has lots of nice customizable options for creating log files depending on how creative you want to be :slight_smile: