views:

73

answers:

3

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!

+3  A: 

Yes, there is a difference. When you run the command from the terminal, it is you who is performing the action, and thus it is performed using your credentials. The Java application is running the command using the Java application's permissions. This is to prevent an application from running and then making dangerous, unwanted changes to the file system. Perhaps someone else can elaborate and give guidance to a workaround for this.

Ryan Hayes
Thanks Ryan! Surely there is a way to run the program within Java. Any ideas on what to do?
James Skidmore
Not sure. It seems like this shouldn't be allowed by design, like ShinTakezou's comment on your question says, for security reasons. Have you tried CarlG's answer? If it works on Linux, then it would definitely be worth a try on Mac OS.
Ryan Hayes
+1  A: 

I'd guess that chmod is a shell command, not an executable. Try running chmod through your shell. See more details here: http://stackoverflow.com/questions/1410741/want-to-invoke-a-linux-shell-command-from-java

CarlG
Thank you so much Carl, it worked perfectly to run it with bash!
James Skidmore
+2  A: 
putgeminmouth
Thanks for the answer, I appreciate it! I'm running that command, but it's still giving a permission denied error. Any ideas why?
James Skidmore