question

AlessandroPerucchi-4330 avatar image
0 Votes"
AlessandroPerucchi-4330 asked MotoX80 commented

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 commented

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



capture.jpg (198.3 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
I didn't know about Process Monitor, and I've tried it...
this is quite heavy stuff!! Lots of data are gathered here!!! Maybe too much!! :-D

Well, with it, and lots of filtering, etc... I have found the problem...
In my java code I verify if a directory is really a directory and not a file, and since I am working with some shared disk, it didn't recognize the directory as such. I need to change a bit my code!
But now I am on the right track!

And it didn't crash, so the check was simply making sure that everything was stopped gracefully!

Thanks for this tip!

Cheers,
Alessandro

0 Votes 0 ·
MotoX80 avatar image MotoX80 AlessandroPerucchi-4330 ·

Excellent! You should play around with all of the Sysinternals tools. I've been using them since the NT4 days. Some like PageDefrag don't work anymore, but most are invaluable. I've solved a lot of problems with procmon.

0 Votes 0 ·