首页 > 解决方案 > Java DefaultExecutor 在 Windows 7 上的长路径上失败错误 = 267

问题描述

环境:

下面的命令在 Windows 7 上完美运行:

C:\Users\dev\Documents\projects\projectx_solution\java\projectx\build\bin\squeezer -R 1 C:\Users\dev\Documents\work\w1\SPOH_ANO12_PDC2.fast -L \\?\c:\Users\dev\Documents\jira\work\ABC04214017-long-path-qwertyuioplkjhgfdsazxcvbnm\qwertyuioplkjhgfdsazxcvbnm2\qwertyuioplkjhgfdsazxcvbnm3\qwertyuioplkjhgfdsazxcvbnm-qwertyuioplkjhgfdsazxcvbnm4\qwertyuioplkjhgfdsazxcvbnm5\qwertyuioplkjhgfdsazxcv\qwertypoiuyalskdjfhg\ABC04214017_03.raw_fhhzcqaj_wLM(4)\objs\RemPartic.fast -H 100000

但是,当我尝试通过 Java 的 DefaultExecutor 运行相同的命令时

 executor.execute(cmdLine);

然后我得到以下IOException

“无法运行程序....创建进程错误=267,目录名无效”。

这在某种程度上与 Windows 长路径限制有关。有谁知道解决方案/解决方法?谢谢!

标签: javawindows

解决方案


您可以使用普通的旧 java 尝试此操作:

        Runtime runtime = Runtime.getRuntime();
    String[] cmd = { "C:\\Users\\dev\\Documents\\projects\\projectx_solution\\java\\projectx\\build\\bin\\squeezer",
            "-R",
            "1",
            "C:\\Users\\dev\\Documents\\work\\w1\\SPOH_ANO12_PDC2.fast",
            "-L",
            "c:\\Users\\dev\\Documents\\jira\\work\\ABC04214017-long-path-qwertyuioplkjhgfdsazxcvbnm\\qwertyuioplkjhgfdsazxcvbnm2\\qwertyuioplkjhgfdsazxcvbnm3\\qwertyuioplkjhgfdsazxcvbnm-qwertyuioplkjhgfdsazxcvbnm4\\qwertyuioplkjhgfdsazxcvbnm5\\qwertyuioplkjhgfdsazxcv\\qwertypoiuyalskdjfhg\\ABC04214017_03.raw_fhhzcqaj_wLM(4)\\objs\\RemPartic.fast",
            "-H",
            "100000"
    };

    Process process = runtime.exec(cmd);
    InputStream in = process.getInputStream();

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String line;

    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }

希望这可以帮助。


推荐阅读