}
theAgent.set(null);
}
protected String executePromptCommand(String command) throws Exception {
AgentMain agent = theAgent.get();
if (agent == null) {
throw new IllegalStateException("Embedded agent is not available");
}
CharArrayWriter listener = new CharArrayWriter();
AgentPrintWriter apw = agent.getOut();
try {
apw.addListener(listener);
agent.executePromptCommand(command);
} catch (Exception e) {
throw new ExecutionException(listener.toString(), e); // the message is the output, cause is the thrown exception
} finally {
apw.removeListener(listener);
}