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

前端 未结 2 1696
遇见更好的自我
遇见更好的自我 2021-01-23 16:02

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 m

相关标签:
2条回答
  • 2021-01-23 16:14

    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.

    0 讨论(0)
  • 2021-01-23 16:21

    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.

    0 讨论(0)
提交回复
热议问题