I am wanting to start my Java program from a batch file. This is the script I want to use to start the app but the problem is that I am not able to get the console output to redirect to a log file. Can anyone offer any hints without having to edit any code, and by using Java command line options or something?
@echo off
set TASK=MyApp
TITLE %TASK%
start javaw.exe -cp .;Server.jar;Util.jar com.manage.Program %1 > log.log 2>&1
taskkill /T /FI "WINDOWTITLE eq %TASK%"
So, the above works, and actually kills the cmd window that spawns my Swing app, but it doesn't log anything to the log file, presumably because the "start" forked the process away from the "> log.log 2>&1" arg?
I could probably fix it by using start to call another batch file but I am hoping for a more elegant answer.
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)