开发者

exception never thrown byExec method in java

I m trying to开发者_开发知识库 exceute system commands such as exp to backup a db.But if the login details are wrong or if the db does not exist then it does not throw an exception.

How can i handle this sort of cases where exceptions are thrown.

All the helpul hands are welcomed..

Regards, Swarupa


You should check the exit value of the system command instead.


Usually, system commands return exit code. If code is 0, then the work comleted sucesfully. Otherwise, you should analyze the exit code and print the respective error message.

int result = Runtime.getRuntime().exec("dir").exitValue();

if (result != 0) {
 // error handling
}


You should check the output of your program. The Runtime.getRuntime().exec() function returns a Process object, which can be used to retrieve the InputStream and the ErrorStream.

Capture the output written to those streams and analyze it to get the errors. Maybe the exit code of the process will help you, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜