diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/classpath/ext/javax/isolate/Isolate.java jnode-devel/trunk/core/src/classpath/ext/javax/isolate/Isolate.java --- jnode-CLEAN/trunk/core/src/classpath/ext/javax/isolate/Isolate.java 2007-06-29 22:08:26.000000000 -0700 +++ jnode-devel/trunk/core/src/classpath/ext/javax/isolate/Isolate.java 2007-09-08 23:28:49.000000000 -0700 @@ -58,6 +58,7 @@ * * @param mainClass * @param args + * @param properties */ public Isolate(Properties properties, String mainClass, String[] args) { this(new StreamBindings(), properties, mainClass, args); @@ -68,10 +69,8 @@ * * @param mainClass * @param mainArgs - * @param context - * @param stdin - * @param stdout - * @param stderr + * @param bindings + * @param properties */ public Isolate(StreamBindings bindings, Properties properties, String mainClass, String[] args) { diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/core/org/jnode/vm/IOContext.java jnode-devel/trunk/core/src/core/org/jnode/vm/IOContext.java --- jnode-CLEAN/trunk/core/src/core/org/jnode/vm/IOContext.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/core/src/core/org/jnode/vm/IOContext.java 2007-09-13 22:05:09.000000000 -0700 @@ -7,18 +7,91 @@ import java.io.PrintStream; /** - * @author Levente Sántha + * This interface provides the hooks for implementing special semantics for System.in, System.out + * and System.err. Specifically, it is used to implement 'proclet' mode where the stream objects + * are proxies for context specific streams. + * + * @author Levente S\u00e1ntha + * @author crawley@jnode.org */ public interface IOContext { + + /** + * This hook is used to set the 'global' version of System.in; e.g. the one used + * when there is no active proclet context. + * + * @param in the new global System.in + */ void setGlobalInStream(InputStream in); + + /** + * This hook is used to get the 'global' version of System.in. + */ InputStream getGlobalInStream(); + + /** + * This hook is used to set the 'global' version of System.out; e.g. the one used + * when there is no active proclet context. + * + * @param in the new global System.out + */ void setGlobalOutStream(PrintStream out); + + /** + * This hook is used to get the 'global' version of System.out. + */ PrintStream getGlobalOutStream(); + + /** + * This hook is used to set the 'global' version of System.err; e.g. the one used + * when there is no active proclet context. + * + * @param in the new global System.err + */ void setGlobalErrStream(PrintStream err); + + /** + * This hook is used to get the 'global' version of System.err. + */ PrintStream getGlobalErrStream(); + + /** + * This hook is used when "setting" System.in; i.e. via System.setIn(in). + * + * @param in the application supplied value for System.in + */ void setSystemIn(InputStream in); + + /** + * This hook is used when "setting" System.out; i.e. via System.setOut(out). + * + * @param in the application supplied value for System.out + */ void setSystemOut(PrintStream out); + + /** + * This hook is used when "setting" System.err; i.e. via System.setErr(err). + * + * @param in the application supplied value for System.err + */ void setSystemErr(PrintStream err); + + /** + * This hook is used to get the 'real' stream underlying System.in in the current context. + */ + InputStream getRealSystemIn(); + + /** + * This hook is used to get the 'real' stream underlying System.out in the current context. + */ + PrintStream getRealSystemOut(); + + /** + * This hook is used to get the 'real' stream underlying System.err in the current context. + */ + PrintStream getRealSystemErr(); + void enterContext(); + void exitContext(); } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java jnode-devel/trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java --- jnode-CLEAN/trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java 2007-06-29 22:17:53.000000000 -0700 +++ jnode-devel/trunk/core/src/core/org/jnode/vm/isolate/IsolateThread.java 2007-08-30 17:29:14.000000000 -0700 @@ -40,6 +40,9 @@ this.stdout = stdout; this.stderr = stderr; this.stdin = stdin; + System.setIn(stdin); + System.setOut(stdout); + System.setErr(stderr); } /** diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java jnode-devel/trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java --- jnode-CLEAN/trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2007-09-13 19:52:20.000000000 -0700 +++ jnode-devel/trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2007-09-13 20:15:55.000000000 -0700 @@ -114,6 +114,16 @@ * Links passed to the start of this isolate */ private VmDataLink[] dataLinks; + + /** + * The isolate-specific default IO context + */ + private final IOContext vmIoContext = new VmIOContext(); + + /** + * The isolate-specific switchable IO context + */ + private IOContext ioContext = vmIoContext; /** * Isolate states. @@ -189,10 +199,8 @@ * @param isolate * @param mainClass * @param args - * @param context - * @param stdin - * @param stdout - * @param stderr + * @param bindings + * @param properties */ public VmIsolate(Isolate isolate, VmStreamBindings bindings, Properties properties, String mainClass, String[] args) { @@ -608,4 +616,16 @@ throw new SecurityException("Method called by invalid isolate"); } } + + public IOContext getIOContext() { + return ioContext; + } + + public void setIOContext(IOContext context) { + ioContext = context; + } + + public void resetIOContext() { + ioContext = vmIoContext; + } } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java jnode-devel/trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java --- jnode-CLEAN/trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java 2007-06-29 22:17:51.000000000 -0700 +++ jnode-devel/trunk/core/src/core/org/jnode/vm/isolate/VmStreamBindings.java 2007-09-13 21:06:07.000000000 -0700 @@ -13,6 +13,8 @@ import java.io.PrintStream; import java.net.Socket; +import org.jnode.vm.IOContext; + /** * Class used to pass stdout/stderr/stdin streams to a new isolate. * @author Ewout Prangsma (epr@users.sourceforge.net) @@ -88,11 +90,12 @@ final PrintStream createIsolatedOut() throws IOException { final OutputStream stream; if (outStream != null) { - stream = new FilterOutputStream(outStream); + stream = new FilterOutputStream(outStream); } else if (outSocket != null) { - stream = new FilterOutputStream(outSocket.getOutputStream()); + stream = new FilterOutputStream(outSocket.getOutputStream()); } else { - stream = new FilterOutputStream(System.out); + IOContext ioContext = VmIsolate.getRoot().getIOContext(); + stream = new FilterOutputStream(ioContext.getRealSystemOut()); } return new PrintStream(stream); } @@ -109,7 +112,8 @@ } else if (errSocket != null) { stream = new FilterOutputStream(errSocket.getOutputStream()); } else { - stream = new FilterOutputStream(System.err); + IOContext ioContext = VmIsolate.getRoot().getIOContext(); + stream = new FilterOutputStream(ioContext.getRealSystemErr()); } return new PrintStream(stream); } @@ -126,7 +130,8 @@ } else if (inSocket != null) { stream = new WrappedInputStream(inSocket.getInputStream()); } else { - stream = new WrappedInputStream(System.in); + IOContext ioContext = VmIsolate.getRoot().getIOContext(); + stream = new WrappedInputStream(ioContext.getRealSystemIn()); } return stream; } @@ -137,6 +142,6 @@ */ public WrappedInputStream(InputStream in) { super(in); - } + } } } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/core/org/jnode/vm/VmIOContext.java jnode-devel/trunk/core/src/core/org/jnode/vm/VmIOContext.java --- jnode-CLEAN/trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/core/src/core/org/jnode/vm/VmIOContext.java 2007-09-13 22:04:21.000000000 -0700 @@ -7,9 +7,10 @@ import java.io.PrintStream; /** - * @author Levente Sántha + * @author Levente S\u00e1ntha + * @author crawley@jnode.org */ -class VmIOContext implements IOContext { +public class VmIOContext implements IOContext { private static InputStream globalInStream; private static PrintStream globalOutStream; private static PrintStream globalErrStream; @@ -54,10 +55,22 @@ } public void enterContext() { - + // No-op } public void exitContext() { - + // No-op } + + public PrintStream getRealSystemErr() { + return System.err; + } + + public InputStream getRealSystemIn() { + return System.in; + } + + public PrintStream getRealSystemOut() { + return System.out; + } } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/core/org/jnode/vm/VmSystem.java jnode-devel/trunk/core/src/core/org/jnode/vm/VmSystem.java --- jnode-CLEAN/trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-09-13 19:52:19.000000000 -0700 +++ jnode-devel/trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-09-06 18:13:41.000000000 -0700 @@ -59,6 +59,7 @@ import org.jnode.vm.classmgr.VmMethod; import org.jnode.vm.classmgr.VmStaticField; import org.jnode.vm.classmgr.VmType; +import org.jnode.vm.isolate.VmIsolate; import org.jnode.vm.memmgr.VmWriteBarrier; import org.jnode.vm.scheduler.VmProcessor; import org.jnode.vm.scheduler.VmThread; @@ -209,15 +210,21 @@ * @return the system output stream */ public static PrintStream getSystemOut() { - if (bootOut == null) { - bootOut = new SystemOutputStream(); - bootOutStream = new PrintStream(bootOut, true); - //globalOutStream = globalErrStream = bootOutStream; - ioContext.setGlobalOutStream(bootOutStream); - ioContext.setGlobalErrStream(bootOutStream); - } - return bootOutStream; + if (bootOut == null) { + bootOut = new SystemOutputStream(); + bootOutStream = new PrintStream(bootOut, true); + IOContext ioContext = getIOContext(); + ioContext.setGlobalOutStream(bootOutStream); + ioContext.setGlobalErrStream(bootOutStream); + return bootOutStream; + } + else if (VmIsolate.isRoot()) { + return bootOutStream; + } + else { + return VmIsolate.currentIsolate().getIOContext().getGlobalOutStream(); + } } /** @@ -328,7 +335,12 @@ * @return String */ public static String getBootLog() { - return bootOut.getData(); + if (bootOut != null) { + return bootOut.getData(); + } + else { + return ""; + } } // ------------------------------------------ @@ -982,7 +994,7 @@ */ @PrivilegedActionPragma public static void setIn(InputStream in) { - ioContext.setSystemIn(in); + getIOContext().setSystemIn(in); } /** @@ -996,7 +1008,7 @@ */ @PrivilegedActionPragma public static void setOut(PrintStream out) { - ioContext.setSystemOut(out); + getIOContext().setSystemOut(out); } /** @@ -1010,7 +1022,7 @@ */ @PrivilegedActionPragma public static void setErr(PrintStream err) { - ioContext.setSystemErr(err); + getIOContext().setSystemErr(err); } //todo protect this method from arbitrary access @@ -1033,11 +1045,15 @@ } //io context related - private static final IOContext vmIoContext = new VmIOContext(); - private static IOContext ioContext = vmIoContext; + // private static final IOContext vmIoContext = new VmIOContext(); + // private static IOContext ioContext = vmIoContext; + + public static IOContext getIOContext() { + return VmIsolate.currentIsolate().getIOContext(); + } public static boolean hasVmIOContext(){ - return ioContext instanceof VmIOContext; + return getIOContext() instanceof VmIOContext; } @@ -1047,7 +1063,7 @@ * @return the global 'err' stream. */ public static PrintStream getGlobalErrStream() { - return ioContext.getGlobalErrStream(); + return getIOContext().getGlobalErrStream(); } /** @@ -1056,7 +1072,7 @@ * @return the global 'in' stream. */ public static InputStream getGlobalInStream() { - return ioContext.getGlobalInStream(); + return getIOContext().getGlobalInStream(); } /** @@ -1065,20 +1081,20 @@ * @return the global 'out' stream. */ public static PrintStream getGlobalOutStream() { - return ioContext.getGlobalOutStream(); + return getIOContext().getGlobalOutStream(); } public static void switchToExternalIOContext(IOContext context){ if (hasVmIOContext()){ - ioContext = context; + VmIsolate.currentIsolate().setIOContext(context); context.enterContext(); } } public static void resetIOContext(){ if (!hasVmIOContext()){ - ioContext.exitContext(); - ioContext = vmIoContext; + getIOContext().exitContext(); + VmIsolate.currentIsolate().resetIOContext(); } else { throw new RuntimeException("IO Context cannot be reset"); } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java jnode-devel/trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java --- jnode-CLEAN/trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-13 23:00:54.000000000 -0700 +++ jnode-devel/trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-31 17:58:38.000000000 -0700 @@ -21,7 +21,6 @@ package org.jnode.driver.console.textscreen; -import java.io.PrintStream; import java.util.Arrays; import org.jnode.driver.console.CompletionInfo; @@ -29,8 +28,6 @@ import org.jnode.driver.console.TextConsole; import org.jnode.driver.console.spi.ConsolePrintStream; -import com.sun.tools.javac.code.Attribute.Array; - /** * A class that handles the content of the current command line in the shell. diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java jnode-devel/trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java --- jnode-CLEAN/trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-31 17:22:44.000000000 -0700 @@ -93,7 +93,8 @@ this, 0x07)); this.savedErr = this.err = new ConsolePrintStream(new ConsoleOutputStream( this, 0x04)); - this.claimSystemOutErr = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR) == 0); +// this.claimSystemOutErr = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR) == 0); + this.claimSystemOutErr = false; this.myIsolate = VmIsolate.currentIsolate(); } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java jnode-devel/trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java --- jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2007-08-02 20:14:22.000000000 -0700 +++ jnode-devel/trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2007-09-08 00:31:56.000000000 -0700 @@ -109,21 +109,17 @@ } else if (newConsole) { if (isolateNewConsole) { try { - Isolate newIsolate = new Isolate(ConsoleCommand.class.getName(), new String[] { "-n" }); + Isolate newIsolate = new Isolate( + ConsoleCommand.IsolatedConsole.class.getName(), + new String[0]); newIsolate.start(); + System.out.println("Started new isolated console"); } catch (IsolateStartupException ex) { System.out.println("Failed to start new isolated console"); ex.printStackTrace(System.err); } } else { - final TextConsole console = (TextConsole) conMgr.createConsole( - null, ConsoleManager.CreateOptions.TEXT - | ConsoleManager.CreateOptions.SCROLLABLE); - CommandShell commandShell = new CommandShell(console); - new Thread(commandShell).start(); - - System.out.println("Console created with name:" - + console.getConsoleName()); + createConsoleWithShell(conMgr); } } else { System.out.println("test RawTextConsole"); @@ -134,4 +130,36 @@ console.clear(); } } + + private static class IsolatedConsole { + + public static void main(String[] args) { + try { + final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); + final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); + TextConsole console = createConsoleWithShell(conMgr); + System.setIn(console.getIn()); + System.setOut(console.getOut()); + System.setErr(console.getErr()); + } + catch (Exception ex) { + // FIXME + System.out.println("Problem creating the isolated console"); + ex.printStackTrace(System.err); + } + } + } + + private static TextConsole createConsoleWithShell(final ConsoleManager conMgr) + throws ShellException { + final TextConsole console = (TextConsole) conMgr.createConsole( + null, ConsoleManager.CreateOptions.TEXT + | ConsoleManager.CreateOptions.SCROLLABLE); + CommandShell commandShell = new CommandShell(console); + new Thread(commandShell).start(); + + System.out.println("Console created with name:" + + console.getConsoleName()); + return console; + } } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/CommandShell.java jnode-devel/trunk/shell/src/shell/org/jnode/shell/CommandShell.java --- jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2007-09-13 21:17:17.000000000 -0700 @@ -192,7 +192,7 @@ defaultCommandInvoker = new DefaultCommandInvoker(this); threadCommandInvoker = new ThreadCommandInvoker(this); procletCommandInvoker = new ProcletCommandInvoker(this); - this.commandInvoker = threadCommandInvoker; // default to separate + setThreadCommandInvoker(); // default to separate this.console.addConsoleListener(this); // threads for commands. aliasMgr = ((AliasManager) InitialNaming.lookup(AliasManager.NAME)) @@ -518,52 +518,58 @@ if (isHistoryEnabled()) { // Insert a filter on the input stream that adds completed input lines // to the application input history. - // TODO - revisit for support of muilt-byte character encodings. - return new FilterInputStream(in) { - private StringBuilder line = new StringBuilder(); - - @Override - public int read() throws IOException { - int res = super.read(); - if (res != -1) { - filter((byte) res); - } - return res; - } - - @Override - public int read(byte[] buf, int offset, int len) throws IOException { - int res = super.read(buf, offset, len); - for (int i = 0; i < res; i++) { - filter(buf[offset + i]); - } - return res; - } - - @Override - public int read(byte[] buf) throws IOException { - int res = super.read(buf); - for (int i = 0; i < res; i++) { - filter(buf[i]); - } - return res; - } - - private void filter(byte b) { - if (b == '\n') { - addInputToHistory(line.toString()); - line.setLength(0); - } - else { - line.append((char) b); - } - } - }; + return new HistoryInputStream(in); } else { return in; } } + + private class HistoryInputStream extends FilterInputStream { + // TODO - revisit for support of multi-byte character encodings. + private StringBuilder line = new StringBuilder(); + + public HistoryInputStream(InputStream in) { + super(in); + } + + @Override + public int read() throws IOException { + int res = super.read(); + if (res != -1) { + filter((byte) res); + } + return res; + } + + @Override + public int read(byte[] buf, int offset, int len) throws IOException { + int res = super.read(buf, offset, len); + for (int i = 0; i < res; i++) { + filter(buf[offset + i]); + } + return res; + } + + @Override + public int read(byte[] buf) throws IOException { + int res = super.read(buf); + for (int i = 0; i < res; i++) { + filter(buf[i]); + } + return res; + } + + private void filter(byte b) { + if (b == '\n') { + addInputToHistory(line.toString()); + line.setLength(0); + } + else { + line.append((char) b); + } + } + } public PrintStream getOutputStream() { return out; diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java jnode-devel/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java --- jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletContext.java 2007-08-30 00:28:55.000000000 -0700 @@ -304,4 +304,17 @@ public Throwable getUncaughtException() { return uncaughtException; } + + /** + * Return a human-readable String representing this ProcletContext. + * @return a human-readable String representing this ProcletContext + */ + public String toString() + { + return getClass().getName() + + "[name=" + getName() + ",maxpri=" + getMaxPriority() + + ",pid=" + getPid() + ']'; + } + + } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java jnode-devel/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java --- jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/shell/src/shell/org/jnode/shell/proclet/ProcletIOContext.java 2007-09-13 22:04:58.000000000 -0700 @@ -9,7 +9,8 @@ import org.jnode.vm.VmSystem; /** - * @author Levente Sántha + * @author Levente S\u00e1ntha + * @author crawley@jnode.org */ public class ProcletIOContext implements IOContext { private static InputStream globalInStream; @@ -117,4 +118,31 @@ VmSystem.setStaticField(System.class, "out", out); VmSystem.setStaticField(System.class, "err", err); } + + public PrintStream getRealSystemErr() { + ProcletContext procletContext = ProcletContext.currentProcletContext(); + if (procletContext != null) { + return (PrintStream) procletContext.getStream(2); + } else { + return globalErrStream; + } + } + + public InputStream getRealSystemIn() { + ProcletContext procletContext = ProcletContext.currentProcletContext(); + if (procletContext != null) { + return (InputStream) procletContext.getStream(0); + } else { + return globalInStream; + } + } + + public PrintStream getRealSystemOut() { + ProcletContext procletContext = ProcletContext.currentProcletContext(); + if (procletContext != null) { + return (PrintStream) procletContext.getStream(1); + } else { + return globalOutStream; + } + } } diff -Naur --exclude-from=exclude jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java jnode-devel/trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java --- jnode-CLEAN/trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-08-23 22:34:02.000000000 -0700 +++ jnode-devel/trunk/shell/src/shell/org/jnode/shell/ProcletCommandInvoker.java 2007-08-30 18:12:06.000000000 -0700 @@ -29,6 +29,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import org.jnode.shell.help.Help; @@ -62,12 +63,15 @@ cmdName); } - Runnable createRunner(Class cx, Method method, Object[] args, InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { - return new CommandRunner(cx, method, args); + Runnable createRunner(Class cx, Method method, Object[] args, + InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { + return new CommandRunner(cx, method, args,commandIn, commandOut, commandErr); } class CommandRunner implements Runnable { - + private final InputStream commandIn; + private final PrintStream commandOut; + private final PrintStream commandErr; private Class cx; Method method; @@ -76,16 +80,28 @@ boolean finished = false; - public CommandRunner(Class cx, Method method, Object[] args) { + public CommandRunner(Class cx, Method method, Object[] args, + InputStream commandIn, PrintStream commandOut, PrintStream commandErr) { this.cx = cx; this.method = method; this.args = args; + this.commandIn = commandIn; + this.commandOut = commandOut; + this.commandErr = commandErr; } public void run() { try { try { - Object obj = null; + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + System.setOut(commandOut); + System.setErr(commandErr); + System.setIn(commandIn); + return null; + } + }); + Object obj = null; if(!Modifier.isStatic(method.getModifiers())) { obj = cx.newInstance(); }