Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have seen this bizarre behavior in windows server 2012 which is running a batch file which has only java -version command. Task is scheduled to run under SYSTEM account.

Content of Batch File.

C#
@ECHO OFF

set CLASSPATH=%CLASSPATH%;"C:\java\jre7\bin\javaw.exe;.\activation.jar;.\mail.jar;.\;.\jt400.jar;" 

java -version >> E:\Interface\IF26_ForecastUpload\TEST\LOG\TEST_IF26_LOG.txt 2>&1

When Task is scheduled to run once a day I get java version info in log file.

If I change the task to run multiple times then I get 'java' is not recognized as internal or external command error in log. At this point I did not make any changes to batch file. Only changed scheduled task to run every hour.

Why is this the case ? I tried same thing on different server and same issue there. Can anyone with Server 2012 confirm this ? Any solution ?
Posted

1 solution

Probably bacuase the PATH variable is not set to include the directory that contains the java executables. Incidentally your CLASSPATH does not look valid above, you should replace the relative directories with their full absolute paths. Also remove javaw.exe, it is not a path.
 
Share this answer
 
Comments
virang_21 4-Nov-15 16:19pm    
Yes you are right in saying that PATH variable is the issue. After posting this question I did some further testing. PATH is set to include directory pointing to java.exe. The problem is when scheduled task is set to run once a day scheduled task pick proper PATH variable with directory to java.exe but when scheduled task is set to run multiple times a day it somehow it excludes anything that was added to PATH in Environment variable except whatever was set by OS. I suspect there is a bug in windows task scheduler in server 2012.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900