I’m trying to embed lucee as one of several scripting engines to use in a Kotlin / +Java application and I’m running into an issue with output handling.
It seems that the Lucee / CFML engine implementations assume you are using it as a CLI if you are creating them directly and I need to figure out how to capture output into a string.
The following code is a simple version of what I’m trying to do:
val scriptEngine = CFMLTagEngineFactoryImpl().scriptEngine
try {
println(scriptEngine.javaClass.canonicalName)
val output = StringWriter()
scriptEngine.context.writer = output
println("----- OUTPUT ------------------------------")
println(output.buffer)
println("----- /OUTPUT ------------------------------")
val value = scriptEngine.eval("<cfoutput>#Now()#</cfoutput>")
} catch (exception:Exception) {
exception.printStackTrace()
}
In the code above, you can see where I’m setting the writer in the script context, which has no affect on the results, but with all the other scripting engines actually captures the output for me to a string that I can then use.
I am willing to fix this myself in the lucee code and submit a pull request, but I could use some advice to speed things up. My only other option is to wrap a savecontent or function around it all, but it will still output tons of blank lines into my console.
I would appreciate any advice or suggestions!