简体   繁体   中英

Unable to run a program in PATH from Java code

I am developing a Red5 media server application on a Mac (Dynamic Web Project in Eclipse). The app has to invoke FFMPEG to convert the video to a different format.

I added "/Applications/FFMPEG" to PATH variable by running the following command in Terminal:

echo 'export PATH=/Applications/FFMPEG:$PATH' >> ~/.profile

When I invoke FFMPEG from terminal, it works fine. However, every time I run it from Java code with:

Process p = Runtime.getRuntime().exec("ffmpeg");
p.waitFor();

I get the following error:

Cannot run program "ffmpeg": error=2, No such file or directory

I thought this might be a security limitation specific to the type of project, but even a simple Java program produces the same result. What am I missing?


Changing "ffmpeg" to full path of the application works, but I don't want to upload FFMPEG into the same directory as Red5 on a production server.

PATH is a command prompt thing. Java knows nothing about paths.

Specify the full path (ie the absolute path) of your executable

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM