captureStdout

fun captureStdout(block: () -> Unit): String

Captures everything printed to System.out during execution of block and returns it as a String.

Not thread-safe: this replaces the process-wide System.out while block runs, so output from other threads is captured too, and concurrent calls interfere with each other. Output is encoded and decoded as UTF-8.

Return

the captured stdout output

Parameters

block

the code to execute while capturing stdout