01: package gnu.jemacs.buffer;
02:
03: import java.io.*;
04:
05: /** Inferior process (external command) mode. */
06:
07: public class InfProcessMode extends ProcessMode {
08: Process proc;
09:
10: InputStream out;
11: InputStream err;
12: OutputStream in;
13:
14: public InfProcessMode(Buffer buffer, String command) {
15: this .buffer = buffer;
16: processMark = new Marker(buffer.pointMarker);
17:
18: try {
19: proc = Runtime.getRuntime().exec(command);
20: } catch (Exception ex) {
21: throw new gnu.mapping.WrappedException("cannot run "
22: + command, ex);
23: }
24: in = proc.getOutputStream();
25: out = proc.getInputStream();
26: err = proc.getErrorStream();
27: toInferior = new OutputStreamWriter(in);
28: Thread outThread = new InputStreamHandler(out, this );
29: outThread.setPriority(Thread.currentThread().getPriority() + 1);
30: outThread.start();
31: Thread errThread = new InputStreamHandler(err, this );
32: errThread.setPriority(Thread.currentThread().getPriority() + 1);
33: errThread.start();
34: }
35:
36: public static void shellMode(Buffer buffer, String command) {
37: buffer.modes = new InfProcessMode(buffer, command);
38: }
39: }
|