running an Executable file and then waiting for that particular exe file to no longer be running

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 11:06:04

问题


I want to run an AHK executable and then have java wait for that executable to terminate it's own process at the end of it's script and then continue, is there a function to monitor whether or not a particular exe is running? And if it's running to wait until it has stopped?

for example in AHK you could do:

IfExist, Appname, 
{
insert code
}

I would do this project using just AHK but because AHK is so flimsy with variables and incrementing i can't get it to work it's IF and Else Statements properly

or if even possible, how can i make Java pause itself for a period of time

all im really looking for is a simple bit of code to run a .exe and the a bit fo code to wait for it to not exist


回答1:


It is as simple as one line of code:

Runtime.getRuntime().exec(<insert executable file here>).waitfor();

PS: It is just one line so I didn't mind, but this is not a place to obtain full working code from others. The usual response is "look here, do it yourself", unless the OP post relevant code with a small part missing, which is not the case here.
PS2: Please consider accepting Jim's answer as it was the correct one.




回答2:


You want to read up on java.lang.ProcessBuilder to launch the exe file and then java.lang.Process.waitFor() to wait until the process is complete. If you want to feed data to the process via its stdin, or read its stdout or stderr, then you have a much more complex task involving threads to handle the streams so that the process doesn't block.



来源:https://stackoverflow.com/questions/5761652/running-an-executable-file-and-then-waiting-for-that-particular-exe-file-to-no-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!