22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 package jdk.jshell.execution; |
25 package jdk.jshell.execution; |
26 |
26 |
27 import java.io.IOException; |
|
28 import java.io.InputStream; |
27 import java.io.InputStream; |
29 import java.io.OutputStream; |
28 import java.io.OutputStream; |
30 import java.io.PrintStream; |
29 import java.io.PrintStream; |
31 import java.lang.reflect.Method; |
30 import java.lang.reflect.Method; |
32 import java.net.Socket; |
31 import java.net.Socket; |
56 * @param args standard command-line arguments, expectation is the socket |
55 * @param args standard command-line arguments, expectation is the socket |
57 * number is the only argument |
56 * number is the only argument |
58 * @throws Exception any unexpected exception |
57 * @throws Exception any unexpected exception |
59 */ |
58 */ |
60 public static void main(String[] args) throws Exception { |
59 public static void main(String[] args) throws Exception { |
61 InputStream fd0 = System.in; |
|
62 String loopBack = null; |
60 String loopBack = null; |
63 Socket socket = new Socket(loopBack, Integer.parseInt(args[0])); |
61 Socket socket = new Socket(loopBack, Integer.parseInt(args[0])); |
64 InputStream inStream = socket.getInputStream(); |
62 InputStream inStream = socket.getInputStream(); |
65 OutputStream outStream = socket.getOutputStream(); |
63 OutputStream outStream = socket.getOutputStream(); |
66 Map<String, Consumer<OutputStream>> outputs = new HashMap<>(); |
64 Map<String, Consumer<OutputStream>> outputs = new HashMap<>(); |
67 outputs.put("out", st -> System.setOut(new PrintStream(st, true))); |
65 outputs.put("out", st -> System.setOut(new PrintStream(st, true))); |
68 outputs.put("err", st -> System.setErr(new PrintStream(st, true))); |
66 outputs.put("err", st -> System.setErr(new PrintStream(st, true))); |
69 outputs.put("echo", st -> { |
|
70 new Thread(() -> { |
|
71 try { |
|
72 int read; |
|
73 |
|
74 while ((read = fd0.read()) != (-1)) { |
|
75 st.write(read); |
|
76 } |
|
77 } catch (IOException ex) { |
|
78 ex.printStackTrace(); |
|
79 } finally { |
|
80 try { |
|
81 st.close(); |
|
82 } catch (IOException ex) { |
|
83 ex.printStackTrace(); |
|
84 } |
|
85 } |
|
86 }).start(); |
|
87 }); |
|
88 Map<String, Consumer<InputStream>> input = new HashMap<>(); |
67 Map<String, Consumer<InputStream>> input = new HashMap<>(); |
89 input.put("in", st -> System.setIn(st)); |
68 input.put("in", st -> System.setIn(st)); |
90 forwardExecutionControlAndIO(new RemoteExecutionControl(), inStream, outStream, outputs, input); |
69 forwardExecutionControlAndIO(new RemoteExecutionControl(), inStream, outStream, outputs, input); |
91 } |
70 } |
92 |
71 |