简体   繁体   English

无法从 Java 代码在 PATH 中运行程序

[英]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).我正在 Mac 上开发 Red5 媒体服务器应用程序(Eclipse 中的动态 Web 项目)。 The app has to invoke FFMPEG to convert the video to a different format.该应用程序必须调用 FFMPEG 才能将视频转换为不同的格式。

I added "/Applications/FFMPEG" to PATH variable by running the following command in Terminal:我通过在终端中运行以下命令将“/Applications/FFMPEG”添加到 PATH 变量:

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

When I invoke FFMPEG from terminal, it works fine.当我从终端调用 FFMPEG 时,它工作正常。 However, every time I run it from Java code with:但是,每次我从 Java 代码运行它时:

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.我认为这可能是特定于项目类型的安全限制,但即使是一个简单的 Java 程序也会产生相同的结果。 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.将“ffmpeg”更改为应用程序的完整路径有效,但我不想将 FFMPEG 上传到生产服务器上与 Red5 相同的目录中。

PATH is a command prompt thing. PATH是命令提示符的东西。 Java knows nothing about paths. Java 对路径一无所知。

Specify the full path (ie the absolute path) of your executable指定可执行文件的完整路径(即绝对路径)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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