I have checked that the output redirection works with javaw
:
javaw -cp ... mypath.MyClass ... arguments 1>log.txt 2>err.txt
It means, if the Java application prints out anything via System.out or System.err, it is written to those files, as also with using java (without w
). Especially on starting java
, the JRE may write starting errors (class not found) on the error output pipe. In this respect, it is essential to know about errors. I suggest to use the console redirection in any case if javaw
is invoked.
In opposite if you use
start java .... 1>log.txt 2>err.txt
With the Windows console start
command, the console output redirection does not work with java
nor with javaw
.
Explanation why it is so: I think that javaw
opens an internal process in the OS (adequate using the java.lang.Process class), and transfers a known output redirection to this process. If no redirection is given on the command line, nothing is redirected and the internal started process for javaw
doesn't have any console outputs. The behavior for java.lang.Process is similar. The virtual machine may use this internal feature for javaw
too.
If you use 'start', the Windows console creates a new process for Windows to execute the command after start, but this mechanism does not use a given redirection for the started sub process, unfortunately.