admin管理员组文章数量:1387356
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
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
Share Improve this question edited Jun 30, 2012 at 2:15 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Apr 23, 2011 at 2:07 Game_Tester_1993Game_Tester_1993 131 silver badge4 bronze badges2 Answers
Reset to default 4You 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 plete. If you want to feed data to the process via its stdin, or read its stdout or stderr, then you have a much more plex task involving threads to handle the streams so that the process doesn't block.
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.
本文标签:
版权声明:本文标题:java - running an Executable file and then waiting for that particular exe file to no longer be running - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744544804a2611832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论