I would like to evaluate Kotlin code on the JVM an...
# scripting
j
I would like to evaluate Kotlin code on the JVM and just get the printed output. What's the easiest way to do it ? I tried playing with
BasicJvmScriptingHost
but I get a lot of weird errors and lost already so much time on this... In the end I just want a function that takes a String input (kotlin code) and outputs the printed output of the evaluated code, i.e:
Copy code
evaluate("""println("Hello World")""") // returns "Hello World"
i
There is no special i/o capturing for scripting, but since the script is compiled into a class and executed as a regular code on the host JVM, you can use standard capturing by assigning to
System.out
and friends.