什么是意义如果流程返回零或一

时间:2018-03-13 11:51:27

标签: java io processbuilder postgresql-9.2

我已经编写了Java代码来获取POSTGRESQL,但程序执行正常而没有错误,p.exitValue()返回Zero.But备份文件没有创建.Below是代码

Runtime rt = Runtime.getRuntime();
Process p;
ProcessBuilder pb;
rt = Runtime.getRuntime();

pb = new ProcessBuilder(
    "/home/Java Softwares/postgres_setup/pgsql/bin/pg_dump",
    "--version", "9.2.18",
    "--host", "2BrigHQ",
    "--port", "5432",
    "--username", "postgres",
    "--no-password",
    "--dbname", "postfixdb",
    "--format", "plain",
    "--blobs",
    "--verbose",
    "--file",
    "/usr/backup/" + backupdate + "_pg_backup.sql");
try {
    final Map < String, String > env = pb.environment();
    env.put("PGPASSWORD", "admin");
    p = pb.start();

    final BufferedReader r = new BufferedReader(
        new InputStreamReader(p.getErrorStream()));
    String line = r.readLine();

    while (line != null) {
        System.err.println(line);
        line = r.readLine();

    }

    r.close();
    p.waitFor();
    System.out.println(p.exitValue());
    System.out.println("backup successfull");
} catch (IOException | InterruptedException e) {
    System.out.println(e.getMessage());
}

0 个答案:

没有答案