Task scheduler start a task and shows running, but nothing happens

Alessandro Perucchi 26 Reputation points
2020-08-25T09:10:40.597+00:00

Hello,

I am trying to run a java program through the task scheduler on an old windows server 2012R2.
My script runs when I double click on it, or if I run directly from the CMD screen.
This is a batch program that doesn't need any interaction with the user, nor does it display anything on the screen. Really a pure batch, command line script.

When running it through the task scheduler, it says that everything runs fine. I've checked the Event Log, and I can see that it was started, and also that it finished successfully. Everything is finished in less than one second.
My script needs to run for at least 20 days... so be finished in less that 1 second, this is not normal.

I've added some output redirection, added an "ECHO Start" and "ECHO End", and in the output file, I can see the Start and the End, but nothing on the Java part.
Like it was "discarded" somehow.

In the Task Scheduler, it works if I select "Run only when user is logged on"
But it doesn't work for "Run whether user is logged on or not". It doesn't matter if the "Do not store password" is selected or not, or if the "Run with highest privileges" is selected or not... I've tried them all... :-(

Obviously for my case, I need that it is started even if I am not logged on...

Here is my batch file:

echo START > D:\my_log.txt 2>&1
set CLASSPATH=XXXXX
"C:\Program Files\AdoptOpenJDK\jre-8.0.265.01-hotspot\bin\java.exe" -cp %CLASSPATH% com.exporting.ExportAll %* >> D:\my_log.txt 2>&1
echo END >> D:\my_log.txt 2>&1

I've tried with another small Java program, and it works with the task scheduler and without.

Now I am a bit in a very strange situation, where I have no clue on why it does work for some Java programs, and for others it doesn't work at all...
Does anybody has any idea how I can debug that?

Thank you very much in helping for this very frustrating situation....

Cheers,
Alessandro

Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,530 questions
0 comments No comments
{count} vote

Accepted answer
  1. MotoX80 31,581 Reputation points
    2020-08-25T12:44:13.777+00:00

    Since you are capturing both stdout and stderr, I would expect java.exe to write something into your log file. I wonder if it's crashing. Try tracing it with Process Monitor.

    Start procmon, click on the capture icon, run the task and then immediately stop the capture. It will trace everything.

    In the path column you should see cmd.exe writing to your log file, and then launch a java.exe process. Look at the entries for java.exe and see if there are any "ACCESS DENIED" or "NOT FOUND" while it's trying to load your application. If you see any references to "WER", that's Windows error reporting, java must be crashing.

    20274-capture.jpg


0 additional answers

Sort by: Most helpful