【发布时间】:2019-05-06 07:39:33
【问题描述】:
我需要在 java(Windows) 中编写一个应用程序,它将运行带有 -P 参数的 pgbench 命令并从控制台读取输出。
我写了 .bat 文件“windowsPostgr.bat”:
设置“PGUSER=postgres”设置“PGPASSWORD=postgres”pgbench -c 1 -f C:/work/EasySQL.sql -j 1 -t 1500 -P 1 -U postgres mydb
还有我的代码:
String cmd = "cmd /c C:\\windowsPostgr.bat";
Process process = Runtime.getRuntime().exec(cmd);
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
int exitCode = process.waitFor();
System.out.println("\nExited with error code : " + exitCode);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
结果,在cmd中运行jar时,只显示生成的pgbenh信息:
事务类型:自定义查询缩放因子:1 查询模式:简单 客户端数:1 线程数:每 1 个事务数 客户端:1500 实际处理的事务数:1500/1500 平均延迟:11.181 毫秒延迟标准开发:1.200 毫秒 tps = 89.073332 (包括建立连接)tps = 89.404427(不包括 建立连接)
然而,当 windowsPostgr.bat 由句柄启动时,会显示以下形式的附加信息(由于 -P 参数):
进度:1.0 秒,76.8 tps,纬度 12.147 毫秒 stddev 1.356
进度:2.0 s,84.1 tps,lat 11.864 ms stddev 1.034 等
其实问题是:从IDEA或jar运行windowsPostgr.bat时如何显示附加信息? reader.readLine() 会读取并显示这些信息吗?
【问题讨论】:
标签: java