Class ShellHelper


  • public class ShellHelper
    extends java.lang.Object
    A helper class for the shell accessor module. It provides functionality to invoke a command and control stdin and stdout. It forks off a process that executes the specified command. A reader thread listens to the process' output and forwards them via the EventEmitter subsystem ('message' event) to the shell.js module in Nashorn. A wait thread waits until the process exits and emits a 'close' event containing the process' exit value.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Armin Wasicek
    Pt.AcceptedRating:
    Red (bilung)
    Pt.ProposedRating:
    Yellow (eal)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ShellHelper createShell​(jdk.nashorn.api.scripting.ScriptObjectMirror scriptObjectMirror, java.lang.String command)
      Factory method to create a new shell.
      void start()
      Start the process and the reader thread.
      void wrapup()
      Kill the process and the reader thread.
      void write​(java.lang.String input)
      Write to the stdin of the process.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createShell

        public static ShellHelper createShell​(jdk.nashorn.api.scripting.ScriptObjectMirror scriptObjectMirror,
                                              java.lang.String command)
        Factory method to create a new shell.
        Parameters:
        scriptObjectMirror - The JavaScript instance invoking the shell.
        command - The command to be executed.
        Returns:
        a new shell.
      • write

        public void write​(java.lang.String input)
                   throws java.io.IOException
        Write to the stdin of the process.
        Parameters:
        input - The data to be sent to the process.
        Throws:
        java.io.IOException - If the string cannot be written.
      • start

        public void start()
        Start the process and the reader thread. Call this after initialization and all callbacks have been installed. TODO: get the exit value of the process.
      • wrapup

        public void wrapup()
                    throws java.io.IOException
        Kill the process and the reader thread.
        Throws:
        java.io.IOException - Not thrown in this base class.