[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]java使用ProcessBuilder,没有输出内容

上一篇:[备忘]log4j,No appenders could be found for logger简单处理
下一篇:[备忘]JDK1.8调https报错:No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

添加日期:2023/3/1 16:42:18 快速返回   返回列表 阅读224次


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();
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved