我在我的文件目录中创建了快捷方式来运行startNetworkServer和我的jar文件。 这是两个serparate快捷方式,然后我在一个批处理文件中运行。 我的批处理文件启动网络服务器,然后等待5秒钟ping 1.1.1.1,然后运行jar文件,从而打开我的java GUI。
我的问题是,我希望在关闭我的java GUI程序后再次停止网络服务器。 为此,我知道我可以运行stopNetworkServer命令,但是,在启动我的jar文件后将其放在批处理文件中会导致网络服务器在jar文件运行之前或之时停止。 我希望它在退出我的java程序时停止。
无论如何我可以检查jar文件是否打开? 或者告诉它等到jar文件关闭? 或者甚至在我的java代码中返回一些东西来启动它?
Ĵ
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
最满意答案
修复了,只需在运行我的Jar文件链接之前添加一个/W前缀。 这意味着下一个过程在完成之前不会开始。
最终批处理文件(.bat)如下所示:
START startNetworkServer.lnk PING 1.1.1.1 -n 1 -w 5000> NUL START / W Run.exe.lnk START stopNetworkServer.lnk
Ĵ
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
更多推荐
发布评论