java - Java DefaultExecutor 在 Windows 7 上的长路径上失败错误 = 267
问题描述
环境:
- Windows 7的
- HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled=1(类型:REG_DWORD)
下面的命令在 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 长路径限制有关。有谁知道解决方案/解决方法?谢谢!
解决方案
您可以使用普通的旧 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);
}
希望这可以帮助。
推荐阅读
- javascript - 访问 react 组件中的 body 以使用 scrollspy
- java - 嵌套HashMap值乘法-Java
- visual-studio - Azure Function 1.x 和 VS17 的 Nuget 问题
- python - 是否可以直接访问原始 numpy 字节?这里的“直接”一词的意思是“不复制”
- bash - 使用 pod 名称执行 Kubernetes pod
- kdb - 如何在 kdb 中将时间戳转换为日期格式
- r - tidyverse 中的 Slice_max
- reactjs - 无法创建反应应用程序,有线错误?
- python - 循环期间打印有问题
- r - R中带有向量和矩阵的自定义函数