Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied error in Java for chmod command

I have an executable file (ffmpeg) that I'm trying to run with a Java program on a Mac. I used the Java program to send the command chmod 777 /path/to/ffmpeg, but when I try to run ffmpeg, I get the following error:

java.io.IOException: Cannot run program "/Users/james/WalkTheHall/ffmpeg": error=13, Permission denied

But when I run chmod 777 /path/to/ffmpeg from Terminal on my own before opening the Java application, the command to ffmpeg will run just fine in the Java program.

Is there a difference between calling chmod from within the Java program and calling it on my own? Why will it not work? Thank you!

like image 489
James Skidmore Avatar asked Jun 21 '10 15:06

James Skidmore


1 Answers

I just had the same problem in my code. i solved this by add waitFor after exec. The "chmod" process is not finished when next command is executed. the code may look like:

p = Runtime.getRuntime.exec("chmod 777 xxx");
p.waitFor();
Runtime.getRuntime.exec("./xxx");
like image 194
macrokigol Avatar answered Oct 11 '22 23:10

macrokigol