I wrote a simple .BAT script, I scheduled it in windows server for backup purposes. The problem is that it runs an application, but the output doesn’t go in the folder it is in, it goes somewhere (I don’t know where). The output is a log file and a backup file.
Here’s the script:
"%JAVA_HOME%"\bin\java -jar "%~dp0jwbackup.jar"
You have two choices. The first is that you can set the current directory for the scheduled task the same way you can specify the executable. This is, of course, an extra thing you need to worry about if the location ever changes.
The other way is shown in your script already. The
%~dp0in your jarfile specification is the drive and path of argument zero (the batch file name) so it looks for the jarfile in the same directory as your batch file.Hence you can just put:
into your command file before attempting to run your Java program and it will be in the correct directory, even if you decide to move it to somewhere else.