简体   繁体   English

无法通过Java运行命令,但可以通过cmd运行 CreateProcess error=2, The system cannot find the file specified

[英]Unable to run command through Java, but can run it through cmd CreateProcess error=2, The system cannot find the file specified

I am unable to convert my mp3s to wavs for easier data manipulation using Java.我无法将我的 mp3 转换为 wav,以便使用 Java 进行更轻松的数据操作。 I can open a command prompt and copy the exact string stored in s when I debug and this will properly create the wav file.我可以打开命令提示符并在调试时复制存储在 s 中的确切字符串,这将正确创建 wav 文件。 The code is below.代码如下。 I was able to use ffmpeg by building strings this way to split up a few mp3s into separate tracks based on a tracklist.我能够通过以这种方式构建字符串来使用 ffmpeg,以根据曲目列表将几个 mp3 分成单独的曲目。 I reinstalled Windows 10, so I'm assuming it has something to do with that.我重新安装了 Windows 10,所以我假设它与此有关。 Is there a setting I have to change?是否有我必须更改的设置? Why would it run in the command prompt, but not with Java?为什么它会在命令提示符下运行,而不是在 Java 中运行?

package mp3towav;

import java.io.File;
import java.io.IOException;

public class Mp3towav {

    // mp3 folder
    public static final String MP3FOLDER = "C:\\Users\\Al\\Documents\\Sounds\\PokemonOST\\YellowOST\\MP3";

    public static void main(String[] args) throws IOException {

        // Gets the mp3 files and converts them to wav
        File mp3folder = new File(MP3FOLDER);

        String[] mp3s = mp3folder.list();

        File f;

        String s; 

        for(int i = 0; i < mp3s.length; i++) {
            f = new File(mp3s[i]);
            s = ("ffmpeg -i " + MP3FOLDER + "\\" + f.getName() + " " + (MP3FOLDER + "\\" + f.getName()).replaceAll("MP3", "WAV").replaceAll("mp3", "wav"));
            Runtime.getRuntime().exec(s);
            System.out.println("test");
        }



    }

}

Edit :编辑

So I never got Java to use PATH, but added in the absolute path to the ffmpeg executable in Java.所以我从来没有让Java使用PATH,而是在Java中添加到ffmpeg可执行文件的绝对路径中。

我不得不添加到 ffmpeg bin 的路径,包括文件名 ffmpeg.exe,而不是让 Java 依赖 Windows 中的 PATH 变量,即使 ffmpeg 在 CMD 窗口中正常工作。

暂无
暂无

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

相关问题 Java执行shell命令-错误[无法运行程序“sh”:CreateProcess错误=2,系统找不到指定的文件] - Java execute shell command - error [Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified] java.io.IOException:无法运行程序“mysql”:CreateProcess error=2,系统找不到指定的文件 - java.io.IOException:Cannot run program “mysql”:CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“”:CreateProcess error = 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“plink”:CreateProcess error=2,系统找不到指定的文件 - java.io.IOException: Cannot run program "plink": CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“sqlldr”:CreateProcess error = 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “sqlldr”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ WMIC”:CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “WMIC”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ tskill”:CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “tskill”: CreateProcess error=2, The system cannot find the file specified 从Java运行python脚本:CreateProcess error = 2,系统找不到指定的文件 - Run a python script from java: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“。\\ bin \\ catalina.bat”-CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “.\bin\catalina.bat” - CreateProcess error=2, The system cannot find the file specified 无法运行程序“ query.sh”:CreateProcess错误= 2,系统找不到指定的文件 - Cannot run program “query.sh”: CreateProcess error=2, The system cannot find the file specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM