Java 带有gunzip的ProcessBuilder不起作用

Java 带有gunzip的ProcessBuilder不起作用,java,processbuilder,gunzip,Java,Processbuilder,Gunzip,我正在尝试运行此代码,但失败原因如下: gzip:/home/idob/workspace/DimesScheduler/*.gz:没有这样的文件或目录 守则: ProcessBuilder gunzipPB = new ProcessBuilder("gunzip", System.getProperty("user.dir") + File.separator + "*"); gunzipPB.inheritIO(); int gunzipProcessExitValue; try {

我正在尝试运行此代码,但失败原因如下:

gzip:/home/idob/workspace/DimesScheduler/*.gz:没有这样的文件或目录

守则:

ProcessBuilder gunzipPB = new ProcessBuilder("gunzip", System.getProperty("user.dir") + File.separator + "*");
gunzipPB.inheritIO();
int gunzipProcessExitValue;

try {
        gunzipProcessExitValue = gunzipPB.start().waitFor();
    } catch (InterruptedException | IOException e) {
        throw new RuntimeException("Service " + this.getClass().getSimpleName() + " could not finish creating WHOIS AS Prefix Table", e);
    }

logger.info("Finished unzipping radb and ripe files. Process exit value : {}", gunzipProcessExitValue);
退出值为1

终端中的相同命令工作正常(文件存在)

有什么问题吗

谢谢

伊多

编辑:

尝试使用DirectoryStrem后,出现以下异常:
java.nio.file.NoSuchFileException:/home/idob/workspace/DimesScheduler/*.gz

知道有什么问题吗?这些文件确实存在

完整代码:

ProcessBuilder radbDownloadPB = new ProcessBuilder("wget", "-q", "ftp://ftp.radb.net    /radb/dbase/*.db.gz");
ProcessBuilder ripeDownloadPB = new ProcessBuilder("wget", "-q", "ftp://ftp.ripe.net/ripe/dbase/split/ripe.db.route.gz"); 

    radbDownloadPB.inheritIO();
    ripeDownloadPB.inheritIO(); 

    try {

        int radbProcessExitValue = radbDownloadPB.start().waitFor();
        logger.info("Finished downloading radb DB files. Process exit value : {}", radbProcessExitValue);

        int ripeProcessExitValue = ripeDownloadPB.start().waitFor();
        logger.info("Finished downloading ripe DB file. Process exit value : {}", ripeProcessExitValue);

        // Unzipping the db files - need to process each file separately since java can't do the globing of '*'  
        try (DirectoryStream<Path> zippedFilesStream = Files.newDirectoryStream(Paths.get(System.getProperty("user.dir"), "*.gz"))){
            for (Path zippedFilePath : zippedFilesStream) {
                ProcessBuilder gunzipPB = new ProcessBuilder("gunzip", zippedFilePath.toString());
                gunzipPB.inheritIO();
                int gunzipProcessExitValue = gunzipPB.start().waitFor();
                logger.debug("Finished unzipping file {}. Process exit value : {}", zippedFilePath, gunzipProcessExitValue);
            }
        }

        logger.info("Finished unzipping ripe and radb DB file");

    } catch (InterruptedException | IOException e) {
        throw new RuntimeException("Service " + this.getClass().getSimpleName() + " could not finish creating WHOIS AS Prefix Table", e);
    }
ProcessBuilder radbDownloadPB=新的ProcessBuilder(“wget”、“-q”、”ftp://ftp.radb.net    /radb/dbase/*.db.gz”);
ProcessBuilder ripeDownloadPB=新的ProcessBuilder(“wget”、“-q”、”ftp://ftp.ripe.net/ripe/dbase/split/ripe.db.route.gz"); 
radbDownloadPB.inheritIO();
ripedownloadp.inheritIO();
试一试{
int radbProcessExitValue=radbDownloadPB.start().waitFor();
info(“已完成下载radb DB文件。进程退出值:{}”,radbProcessExitValue);
int ripeProcessExitValue=ripeDownloadPB.start().waitFor();
info(“已完成下载成熟的DB文件。进程退出值:{}”,ripeProcessExitValue);
//解压db文件-需要单独处理每个文件,因为java无法对“*”进行全局化
try(DirectoryStream-zippedFilestream=Files.newDirectoryStream(path.get(System.getProperty(“user.dir”),“*.gz”)){
对于(路径zippedFilePath:ZippedFileStream){
ProcessBuilder gunzipPB=新的ProcessBuilder(“gunzip”,zippedFilePath.toString());
gunzipPB.inheritIO();
int gunzipProcessExitValue=gunzipPB.start().waitFor();
debug(“已完成解压文件{}。进程出口值:{}”,zippedFilePath,GunZippProcessExitValue);
}
}
info(“已完成对RIME和radb DB文件的解压缩”);
}捕获(中断异常| IOE异常){
抛出新的RuntimeException(“服务”+this.getClass().getSimpleName()+“无法完成创建WHOIS作为前缀表”,e);
}
谢谢…

这个
*.gz
不是由gunzip命令处理的,而是由shell处理的。例如,shell将
gunzip*.gz
转换为
gunzip a.gz b.gz
。现在,当您通过java执行时,您要么调用bash来为您执行globbing,要么在java中扩展glob,因为gzip不知道如何处理glob

Java 7提供了一种更容易扩展全局模式的方法。

gunzip命令不处理
*.gz
,而是由shell处理。例如,shell将
gunzip*.gz
转换为
gunzip a.gz b.gz
。现在,当您通过java执行时,您要么调用bash来为您执行globbing,要么在java中扩展glob,因为gzip不知道如何处理glob


Java 7提供了一个扩展全局模式的工具。

谢谢。正如您所说的,我可以使用java.nio.DirectoryStream,也可以运行类似的东西:newProcessBuilder(“/bin/sh”、“-c”、“gunzip./*”);谢谢正如您所说的,我可以使用java.nio.DirectoryStream,也可以运行类似的东西:newProcessBuilder(“/bin/sh”、“-c”、“gunzip./*”);