简体   繁体   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 run it, but when its used on another server I had the following error while executing ffmpeg: 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)

I tried to change permissions on the ffmpeg.exe file, through Java code such as ffmpegFile.setExecutable(true), File.setReadable(true), File.setWritable(true) but unsuccessfully, also tried to change file permission via my FileZilla software to 777, but again unsuccessfully:我尝试通过 ffmpegFile.setExecutable(true)、File.setReadable(true)、File.setWritable(true) 等 Java 代码更改 ffmpeg.exe 文件的权限,但未成功,还尝试通过我的 FileZilla 软件更改文件权限到 777,但再次失败:

在此处输入图像描述

What is strange is like permission goes back to 750 after server reboot, but even before restart it doesn't work.奇怪的是权限在服务器重新启动后回到 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 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

Here is my code:这是我的代码:

 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(); }

So, I was wondering if there can be any work around to use the library, give the needed permissions, or running it in a certain way that will not trigger permission check.所以,我想知道是否有任何解决方法可以使用该库,提供所需的权限,或者以某种不会触发权限检查的方式运行它。 Thanks you.谢谢。

EDIT:编辑:

Thanks for your replies, I followed the answers, the server is running under unix and now my program looks like:感谢您的回复,我遵循了答案,服务器在 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();
        }

But now I have an strange output when I execute the.exe and I don't know what is:但是现在我执行.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

Thanks for you replies, I figured out how to solve the problem, and why I had problems, for any one coming down here, here is the solution, follow those steps;感谢您的回复,我想出了如何解决问题,以及为什么我遇到问题,对于任何来到这里的人,这里是解决方案,请按照这些步骤操作;

  1. The server isn't running under Windows, as @gpasch said / and the \ are not the same, to get a valid path I had to use apache method, for instance FilenameUtils.separatorsToUnix(new File(softhware.getFolder() + "/libraries/", "ffmpeg").getAbsolutePath()) as a String path to ffmpeg.服务器没有在 Windows 下运行,正如@gpasch 所说 / 和 \ 不一样,要获得有效路径,我必须使用 apache 方法,例如 FilenameUtils.separatorsToUnix(new File(softhware.getFolder() + " /libraries/", "ffmpeg").getAbsolutePath()) 作为 ffmpeg 的字符串路径。

  2. The second error that I had ( see edit post ), comes from the usage of an Windows ffmpeg instead of a Linux/Unix one, so removed it and replaced it by a new one from https://ffbinaries.com/downloads .我遇到的第二个错误(请参阅编辑帖子)来自使用 Windows ffmpeg 而不是 Linux/Unix 错误,因此将其删除并替换为Z5E056C500A1C4B6A7110B50D807BADE.bin中的新错误。 That made me change my program to:这使我将程序更改为:

        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 I got my server deleted, 15 minutes after sucessfully running ffmpeg. Becarfull 我在成功运行 ffmpeg 15 分钟后删除了我的服务器。

暂无
暂无

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

相关问题 詹金斯错误:java.io.IOException:错误=13,权限被拒绝 - Jenkins Error :java.io.IOException: error=13, Permission denied JavaFX java.io.IOException &quot;uptime&quot;: error=13, permission denied - 以普通用户身份运行程序 - JavaFX java.io.IOException "uptime": error=13, permission denied - Running program as regular user W/System.err:java.io.IOException:无法运行程序“python”:错误=13,权限被拒绝 - W/System.err: java.io.IOException: Cannot run program "python": error=13, Permission denied java.io.IOException:关闭XSSFWorkbook时,jenkins中的权限被拒绝 - java.io.IOException: Permission denied in jenkins While Closing XSSFWorkbook java.io.IOException:Java中的权限被拒绝 - java.io.IOException: Permission denied in Java java.io.IOException:createNewFile() 的权限被拒绝 - java.io.IOException: Permission denied for createNewFile() 通过java程序在IBM云中运行shell命令,将抛出java.io.IOException错误:无法运行program = 13,权限被拒绝 - Running a shell command in IBM cloud through java programme throwing error as java.io.IOException: Cannot run program =13, Permission denied 即使在询问权限后,java.io.IOException 权限也被拒绝 - java.io.IOException Permission denied even after asking the permision java.io.IOException:在Andoid上使用相机时权限被拒绝? - java.io.IOException: Permission denied when using Camera on Andoid? java.io.IOException:权限被拒绝但文件已创建 - java.io.IOException: Permission denied but file is created
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM