Ives
Ives

Reputation: 555

Detecting runTime process is finished

I'm using FFmpeg to export the video.
I run the exe file from my java code.

val process = Runtime.getRuntime().exec("$ffmpeg .....)
while (process.isAlive) {
   //waiting
}

if(process.exitValue() != 0) {
//failed
}
else {
//successful
}

If any errors occur in FFmpeg, process will return an exitValue not 0 to tell me there is something wrong.
But when the file or dir includes forbidden characters, it will be a " No such file or directory" error in ffmpeg, however it doesn't return anything to the java program, so the program sticks at process.isAlive part.
Is there a better way to detect the process is finished or not?

Upvotes: 0

Views: 162

Answers (1)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

You can get better control of the Process by using ProcessBuilder and Process classes directly instead of Runtime.getRuntime().exec()

Also, unless it's a typo, you want process.isAlive() instead of process.isAlive (it's a method call, returning a boolean).

Upvotes: 1

Related Questions