我试过在java中运行命令但没有运气
rpm2cpio <rpmName> | cpio -imdv
这是我当前的代码
public static void decompress() {
System.out.println("Decompression has started");
Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
try {
archiver.extract(autoUpdateFile, tempDestination);
for(File currentRPM: new File("./temp/patches/rpms/").listFiles()) {
if(currentRPM.getName().contains("Data")) {
ProcessBuilder decompressRPM = new ProcessBuilder(
new String[] {"rpm2cpio", currentRPM.getAbsolutePath(), "cpio -idmv"});
Process startDecompression = decompressRPM.start();
InputStream inputFromDecompression = startDecompression.getInputStream();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputFromDecompression));
String line = null;
System.out.println("From Input Buffer");
while((line = inputReader.readLine()) != null) {
System.out.println(line);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Decompression ended");
}
主要思想是我有一个压缩文件,其中包含多个文件,其中一个文件中存在一个 rpm 列表,我需要解压缩以获取一些数据以更新项目。
有什么方法可以运行这样的命令还是需要使用库?
谢谢你。
更新:感谢@Brian,我设法通过更改从
ProcessBuilder decompressRPM = new ProcessBuilder(
new String[] {"rpm2cpio", currentRPM.getAbsolutePath(), "cpio -idmv"});
Process startDecompression = decompressRPM.start();
至
String[] decompressionCommand = {"/bin/sh", "-c", "rpm2cpio " + currentRPM.getAbsolutePath() + " | cpio -idmv"};
Process startDecompression = Runtime.getRuntime().exec(decompressionCommand);
但我最终遇到了另一个问题。我的权限被拒绝了。我将四处寻找解决方案,以防万一我找到一些东西,我会在这里发布以供将来参考。