Hi I have a problem to run an external process in java 8. Basically I jave to run ffplay from my java code, and seems that the.destroy() method doesn't work if the external process have child processes.
My code is: '''
ProcessBuilder builder = new ProcessBuilder();
builder.command().add("/usr/bin/fplay");
builder.command().add(".........."); // my args
builder.environment().put("LD_LIBRARY_PATH", myCustomLibraryPath);
Process process = builder.start();
// After
process.destroy();
process.destroyForcibly();
''' But even after doing the destroy() and destroyForcibly() the ffplay window remains open. I tried to use Runtime.getRuntime().exec(......) instead of ProcessBuilder and in this case seems that the destroy method closes the ffplay window. But I don't know how to set LD_LIBRARY_PATH in Runtime.
Is there anyone who can help me terminate the ffplay process with ProcessBuilder or setting LD_LIBRARY_PATH to Runtime.getRuntime().exec(......)?
@dave_thompson_085 I noticed a strange thing, the problem that destroy doesn't work is only with scripts. Let me explain better, if I do this:
ProcessBuilder builder = new ProcessBuilder();
builder.command().add("ffplay");
builder.command().add("/videos/TEST.mp4");
Process process = builder.start();
the destroy() method closes the ffplay window. But if I create a script named myScript.sh with only this line in it:
ffplay /videos/TEST.mp4
and I do:
ProcessBuilder builder = new ProcessBuilder();
builder.command().add("myScript.sh");
Process process = builder.start()
The destroy() method doesn't close the ffplay window.
Last week i had the probelm to kill my batch script which i started with the ProcessBuilder. My solution was
Runtime.getRuntime().exec("taskkill /F /IM cmd.exe")
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.