od怎么解java打包的exe_用java中的ProcessBuilder提取7zip命令

我在使用Java 10 ProcessBuilder和7z.exe(18.05)和命令行将存档文件提取到所需类别时遇到问题。当我使用Windows CMD时,完全相同的命令可以正常工作,但当我的JavaFX应用程序使用ProcessBuilder发出时,它不再起作用:

public static void decompress7ZipEmbedded(File source, File destination) throws IOException, InterruptedException {

ProcessBuilder pb = new ProcessBuilder(

getSevenZipExecutablePath(),

EXTRACT_WITH_FULL_PATHS_COMMAND,

quotifyPath(source.getAbsolutePath()),

OUTPUT_DIRECTORY_SWITCH + quotifyPath(destination.getAbsolutePath())

);

processWithSevenZipEmbedded(pb);

}

private static void processWithSevenZipEmbedded(ProcessBuilder pb) throws IOException, InterruptedException {

LOG.info("7-zip command issued: " + String.join(" ", pb.command()));

Process p = pb.start();

new Thread(new InputConsumer(p.getInputStream())).start();

System.out.println("Exited with: " + p.waitFor());

}

public static class InputConsumer implements Runnable {

private InputStream is;

InputConsumer(InputStream is) {

this.is = is;

}

@Override

public void run() {

try {

int value = -1;

while ((value = is.read()) != -1) {

System.out.print((char) value);

}

} catch (IOException exp) {

exp.printStackTrace();

}

LOG.debug("Output stream completed");

}

}

public static String getSevenZipExecutablePath() {

return FileUtil.quotifyPath(getDirectory() + "7z" + "/" + "7z");

}

public static String quotifyPath(String path) {

return '"' + path + '"';

}

public class Commands {

public static final String EXTRACT_COMMAND = "e";

public static final String EXTRACT_WITH_FULL_PATHS_COMMAND = "x";

public static final String PACK_COMMAND = "a";

public static final String DELETE_COMMAND = "d";

public static final String BENCHMARK_COMMAND = "b";

public static final String LIST_COMMAND = "l";

}

public class Switches {

public static final String OUTPUT_DIRECTORY_SWITCH = "-o";

public static final String RECURSIVE_SWITCH = "-r";

public static final String ASSUME_YES = "y";

}

命令如下所示:

"C:/Users/blood/java_projects/AppRack/target/classes/7z/7z" x "D:\Pulpit\AppRack Sandbox\test\something\Something 2\Something2.7z" -o"D:\Pulpit\AppRack Sandbox\Something2"

以及ProcessBuilder的输出:

7-Zip 18.05 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-04-30

Scanning the drive for archives:

1 file, 59177077 bytes (57 MiB)

Extracting archive: D:\Pulpit\AppRack Sandbox\test\Something\Something 2\Something2.7z

--

Path = D:\Pulpit\AppRack Sandbox\test\Something\Something 2\Something2.7z

Type = 7z

Physical Size = 5917Exited with: 0

7077

Headers Size = 373

Method = LZMA2:26 LZMA:20 BCJ2

Solid = +

Blocks = 2

No files to process

Everything is Ok

Files: 0

Size: 0

Compressed: 59177077

它什么也做不了。没有创建所需的文件夹,没有。使用CMD它就像一个符咒一样工作(这里使用

相同的命令

):

7-Zip 18.05 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-04-30

Scanning the drive for archives:

1 file, 59177077 bytes (57 MiB)

Extracting archive: D:\Pulpit\AppRack Sandbox\test\Something\Something 2\Something2.7z

--

Path = D:\Pulpit\AppRack Sandbox\test\Something\Something 2\Something2.7z

Type = 7z

Physical Size = 59177077

Headers Size = 373

Method = LZMA2:26 LZMA:20 BCJ2

Solid = +

Blocks = 2

Everything is Ok

Folders: 1

Files: 5

Size: 64838062

Compressed: 59177077

你知道是什么导致了这里的差异,为什么它说“没有文件要处理,一切都好”而不做任何事情?我已经尝试过先使用文件类创建文件夹,但这似乎不是问题,因为在提取之前是否存在目标文件夹的结果是相同的。

我已经尝试了所有我想到的东西,但我现在已经没有主意了。请与我分享你对这个问题的任何建议。谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值