在JAVA里调用数据库备份命令——怎么获得返回值?

2dian1G 2003-08-20 10:57:37
Runtime rt = Runtime.getRuntime();
int rc = -1;

try
{
Process proc = rt.exec(cmd);
int bufSize = 10240;
BufferedInputStream bis =
new BufferedInputStream(proc.getInputStream(), bufSize);
int len;
byte buffer[] = new byte[bufSize];

// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);

rc = proc.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
rc = -1;
return false;
}
finally
{
System.out.write(rc);
return true;
}
如果我的命令当中包含的数据库口令是错误的,不能象我直接在CMD窗口中可以得到的提示进行重新输入,这个进程好象始终是处于等待状态,我该怎么解决?多谢指点。

...全文
91 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
joyrush 2003-09-16
  • 打赏
  • 举报
回复
这是怎么解决的啥....
qwater 2003-09-16
  • 打赏
  • 举报
回复
up
2dian1G 2003-08-21
  • 打赏
  • 举报
回复
upup
2dian1G 2003-08-20
  • 打赏
  • 举报
回复
up

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧