簡體   English   中英

java.io.IOException: error=13, Permission denied while execution an.exe library

[英]java.io.IOException: error=13, Permission denied while executing an .exe library

My Java program is running under a hosted server (not mine), the program is using ffmpeg as a video processing library, on my localhost installation I had no trouble while using my program and executing ffmpeg, the program extract the ffmpeg.exe somewhere and運行它,但是當它在另一台服務器上使用時,我在執行 ffmpeg 時出現以下錯誤:

  java.io.IOException: Cannot run program "softwares/player/libraries/ffmpeg.exe": error=13, Permission denied
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
    at com.albert4224.player.Loader.run(TaskAsyncLoadVideo.java:83)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
  Caused by: java.io.IOException: error=13, Permission denied
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)

我嘗試通過 ffmpegFile.setExecutable(true)、File.setReadable(true)、File.setWritable(true) 等 Java 代碼更改 ffmpeg.exe 文件的權限,但未成功,還嘗試通過我的 FileZilla 軟件更改文件權限到 777,但再次失敗:

在此處輸入圖像描述

奇怪的是權限在服務器重新啟動后回到 750,但即使在重新啟動之前它也不起作用。

Maybe related to: Permission denied error in Java for chmod command , I tried running other program that uses.exe library and resulted in a java.io.IOException: Cannot run program "/bin/chmod": error=13, Permission denied

這是我的代碼:

 String[] videoCommand = {new File(softhware.getFolder() + "/libraries/", "ffmpeg.exe").getAbsoluteFile().getAbsolutePath(), "-hide_banner", "-loglevel", "error", "-i", video.getVideoFile().getAbsolutePath(), "-q:v", "0", "-start_number", String.valueOf(framesCount), new File(video.getFramesFolder().getPath(), "%d.jpg").getAbsolutePath()}; ProcessBuilder videoProcessBuilder = new ProcessBuilder(videoCommand); try { Process process = videoProcessBuilder.inheritIO().start(); process.waitFor(); }catch (IOException | InterruptedException e) { e.printStackTrace(); }

所以,我想知道是否有任何解決方法可以使用該庫,提供所需的權限,或者以某種不會觸發權限檢查的方式運行它。 謝謝。

編輯:

感謝您的回復,我遵循了答案,服務器在 unix 下運行,現在我的程序如下所示:

    try {
        
        Runtime.getRuntime().exec("chmod -R 777 " + FilenameUtils.separatorsToSystem(new File(softhware.getFolder() + "/libraries/", "ffmpeg.exe")).getAbsolutePath())).waitFor();
        
             
        Runtime.getRuntime().exec(FilenameUtils.separatorsToSystem(new File(softhware.getFolder() + "/libraries/", "ffmpeg.exe").getAbsolutePath()) + " -hide_banner " + "-loglevel " + "error" + " -i " + video.getVideoFile().getAbsolutePath() + " -q:v " + "0 " +
                    "-start_number " + String.valueOf(framesCount) + " " + new File(video.getFramesFolder().getPath() + "%d.jpg").getAbsolutePath()).waitFor();
        }catch (InterruptedException | IOException e) {
              e.printStackTrace();
        }

但是現在我執行.exe時出現了一個奇怪的output,不知道是什么:

>/home/container/softwares/Player/libraries/ffmpeg.exe: 1: 
MZ����@���: not found
�.ome/container/softwares/Player/libraries/ffmpeg.exe: 2: �
%D����@8: not found
/home/container/softwares/Player/libraries/ffmpeg.exe: 3: Syntax 
error: "(" unexpected

感謝您的回復,我想出了如何解決問題,以及為什么我遇到問題,對於任何來到這里的人,這里是解決方案,請按照這些步驟操作;

  1. 服務器沒有在 Windows 下運行,正如@gpasch 所說 / 和 \ 不一樣,要獲得有效路徑,我必須使用 apache 方法,例如 FilenameUtils.separatorsToUnix(new File(softhware.getFolder() + " /libraries/", "ffmpeg").getAbsolutePath()) 作為 ffmpeg 的字符串路徑。

  2. 我遇到的第二個錯誤(請參閱編輯帖子)來自使用 Windows ffmpeg 而不是 Linux/Unix 錯誤,因此將其刪除並替換為Z5E056C500A1C4B6A7110B50D807BADE.bin中的新錯誤。 這使我將程序更改為:

        try {
            Runtime.getRuntime().exec("chmod -R 777 " + FilenameUtils.separatorsToUnix(new File(software.getFolder() + "/libraries/", "ffmpeg").getAbsolutePath())).waitFor();
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
        }

        String[] videoCommand = {
            FilenameUtils.separatorsToUnix(new File(softhware.getFolder() + "/libraries/", "ffmpeg").getAbsolutePath()),
            "-hide_banner",
            "-loglevel",
            "error",
            "-i",
            FilenameUtils.separatorsToUnix(video.getVideoFile().getAbsolutePath()),
            "-q:v",
            "0",
            "-start_number",
            String.valueOf(framesCount),
            FilenameUtils.separatorsToUnix(new File(video.getFramesFolder().getPath(), "%d.jpg").getAbsolutePath())
        };

        ProcessBuilder videoProcessBuilder = new ProcessBuilder(videoCommand);

        try {
            Process process = videoProcessBuilder.inheritIO().start();
            process.waitFor();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
  1. Becarfull 我在成功運行 ffmpeg 15 分鍾后刪除了我的服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM