See https://github.com/beanshell/beanshell/tree/master/src/main/java/bsh/util
and simplified example here:
https://stackoverflow.com/questions/1255373/create-a-command-console