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);
}
String output = listener.toString();
return output;
}