java - Direct standard output of dynamically compiled & executed code -


background information:

  • i used javax.tools.javacompiler compile code dynamically memory.
  • i used custom class loader load , execute dynamically compiled code.

my question

let's provides following code:

package cs.compile; import java.util.arrays; public class foo {     private static int[] nums = new int[] { 1, 2, 3, 4, 5 };     public static void main(string[] args) {         system.out.println(getwords() + " " + arrays.tostring(nums));     }     public static string getwords() { return "hello world!!!"; } } 

when execute main() via reflection, works fine. standard-out , standard-error results execution , save them in variable can return them result.

i'm not sure how think, once class loaded, shares same standard-out , standard-error rest of application. there standard way of dealing perhaps? don't want direct entire application's output streams away, i'm not sure how target new class.

since you compiling it, can change code... replace system.out :)

or set global system.out custom output stream redirects different destinations, based on heuristics. maybe thread local flag? etc.


Comments

Popular posts from this blog

angularjs - Redirect to a new template in angular js -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

Desktop Launcher for Python Script Starts Program in Wrong Path (Linux) -