简体   繁体   中英

Running jar and database through batch file (Windows)

I have made shortcuts within my file directory to run the startNetworkServer and my jar file. These are two serparate shortcuts that I then run within a single batch file. My batch file starts the network server, then pings 1.1.1.1 with a wait of 5 seconds before then running the jar file, hence opening my java GUI.

My issue is, I wish to stop the network server again upon closing my java GUI program. To do this I know I can run the stopNetworkServer command, however, placing this in the batch file after the starting of my jar file results in the network server stopping before or whilst the jar file is running. I want it to stop upon exiting my java program.

Is there anyway I can check to see if the jar file is open? Or tell it to wait until the jar file is closed? Or even return something in my java code to kick start this?

J

Fixed, just had to add a /W prefix before running my Jar file link. This means that the next process will not start until that one finishes.

The final batch file (.bat) looks like this:

START startNetworkServer.lnk
PING 1.1.1.1 -n 1 -w 5000 >NUL
START /W Run.exe.lnk
START stopNetworkServer.lnk

J

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM