How do I redirect a javaw.exe console output to a log file?
As far as I know using javaw suppresses all System.out.println(...) to the console.
Therefore your application needs to implement logging internally. You could use a wrapper class to redirect the output using System.setOut(...) to write to a file. Then your wrapper class would invoke you other class.
Sometimes your webstart application crashes and you cannot see why because the Console closes with the crash. To enable console logging in Java webstart with JDK 1.6:
Start->Run...->javaws -viewer Close the Java Cache Viewer Advanced tab->Debugging check 'Enable tracing' and 'Enable logging'
You logfiles can now be found in:
C:\Documents and Settings\USER\Application Data\Sun\Java\Deployment\log
It sounds like you want to log console output without actually displaying a console. I can see three ways of doing something similar:
Start console minimized, so that it's less annoying. You can do that by creating a shortcut to a batch file, and then setting the properties of the shortcut to run the batch file in a minimized window instead of using the default setting of "Normal window".
Create a script to run the bat file in a hidden window, like so: http://gallery.technet.microsoft.com/ScriptCenter/en-us/8bbed56f-a7aa-491f-a296-687dd96098a3
Use a third party tool, like hstart. (Note: according to djangofan, hstart was not written for Java programs and does not really work)
Its more simple than you think.
You only need to change the System.out
:
System.setOut(new PrintStream(new FileOutputStream("log.txt",true)));
And that's it!
Good luck.