[英]UniObjects for Java: How to get response String when error occurred in UniCommand.exec()
I would like to be able to determine the exact reason that a UniCommand
could not complete using UniObjects for Java in order to tell the user. 我希望能够确定
UniCommand
无法完成使用UniObjects for Java来告诉用户的确切原因。 I have the following code that behaves as expected under ideal conditions, but if command
is not a valid command, uniCommand.response()
returns an empty String
. 我有以下代码在理想条件下的行为符合预期,但是如果
command
不是有效命令,则uniCommand.response()
返回一个空String
。 I would like to know exactly why the command could not execute. 我想确切地知道为什么命令无法执行。 I tried to use
uniCommand.getSystemReturnCode()
, but it always returns -1
if the command did not complete successfully and that's not enough information. 我尝试使用
uniCommand.getSystemReturnCode()
,但是如果命令未成功完成并且信息不足,它将始终返回-1
。 How do I find out exactly what went wrong? 我如何确切找出问题所在?
UniCommand uniCommand = uniSession.command();
uniCommand.setCommand(command);
uniCommand.exec();
int status = uniCommand.status();
//int sysRet = uniCommand.getSystemReturnCode();
if (status == UniObjectsTokens.UVS_COMPLETE) {
output(uniCommand.response());
}
An Example: When I execute BLAH
via telnet on the UniVerse server itself I get: 一个示例:当我在UniVerse服务器本身上通过telnet执行
BLAH
,我得到:
Verb "BLAH" is not in your VOC.
and when I execute LIST BLAH
I get: 当我执行
LIST BLAH
我得到:
RetrieVe: syntax error. Unexpected sentence without filename. Token was "".
Scanned command was LIST 'BLAH'
I would like to get those exact error messages in my program using UniObjects for Java. 我想使用UniObjects for Java在程序中获取那些确切的错误消息。 Is that possible?
那可能吗?
I have had the same problem, and it does seem like a limitation of the uniobjects library. 我也遇到过同样的问题,这似乎是对uniobjects库的限制。 One way to handle it is to wrap the command in a subroutine.
一种解决方法是将命令包装在子例程中。
SUBROUTINE RUN.COMMAND(COMMAND,RESPONSE)
EXECUTE COMMAND CAPTURING RESPONSE
END
Then use a UniSubroutine object to call it. 然后使用UniSubroutine对象调用它。
String command = "LIST BLAH";
UniSubroutine sub = uniSession.subroutine("RUN.COMMAND", 2);
sub.setArg(0, command);
sub.call();
UniDynArray response = new UniDynArray(sub.getArg(1));
for (int i = 0; i < response.dcount(); i++) {
String line = response.extract(i).toString();
System.out.println(line);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.