1

I am using a Windows executable to do some optimisation tasks. This executable is run from a Windows Command Prompt (cmd). It reads a batch file that tells it how to run a model interface (it will need to run it multiple times) which reads and writes text files for input/output between it and the optimisation .exe program. This model interface is written in java and has been successfully compiled. My batch file looks like this:

java -cp .;"C:\Program Files\location_of_required_jars\*" name_of_class_file

The java program executes and completes without issue.

My issue is that the executable I am running needs to know when java has terminated. At the moment it hangs after 1 run of the model interface java program, waiting for the java ... line to complete.

Can anyone provide advice on how to get java to inform cmd that it has completed?

1
  • It's hard to know what you mean. When the java.exe exits the batch moves to the next line. Commented Jul 12, 2018 at 12:22

1 Answer 1

1

If the batch file does not progress further after running first java command that means that java process has not actually finished. You would need to diagnose the problem, I would suggest to first make sure that it indeed does not finish by adding some echo statement after java invocation. Next you would need to run jps command, which is part of JDK. jps will report PIDs of running java processes and then you do jstack <pid> to find out what is preventing your java program from terminating. It can be that main thread did not actually complete or some non daemon threads are still running.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this - it now seems somewhat obvious. I added an echo statement to my batch file and it is never reached. I have gone back to the .java file and fixed it with System.exit(0); On to the next problem now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.