public static String runPgRestore(String exePath,String bakPath) { //"D:\xxx\pgsql\bin\pg_restore.exe" --no-password -h 127.0.0.1 -U postgres --dbname yyy "F:\xxxBackup\xx\backup.xxx" try { ProcessBuilder p = new ProcessBuilder(exePath, "--no-password", "-h", "127.0.0.1", "-U", "postgres", "--dbname", "yyy", bakPath); p.redirectErrorStream(true); p.redirectOutput(); Process netstat = p.start();
java.io.BufferedReader input = new java.io.BufferedReader(new java.io.InputStreamReader(netstat.getInputStream(), "GBK"));
StringBuilder result = new StringBuilder(); String line = null; while ((line = input.readLine()) != null) { result.append(line).append("\n"); }
input.close(); netstat.destroy(); return result.toString(); } catch (Exception e) { return e.getMessage(); } }
加上这两句就好了: p.redirectErrorStream(true); p.redirectOutput();
|