private synchronized boolean open() {
      try {
        // setup our process, retrieve stdin stream, and stdout/stderr gobblers
        process = runWithEnv(shell, environment);
        stdin = new DataOutputStream(process.getOutputStream());
        stdout = new StreamGobbler(process.getInputStream(), new StreamGobbler.OnLineListener() {

          @Override
          public void onLine(String line) {
            synchronized (Interactive.this) {
              if (command == null) {
                return;
              }

              String contentPart = line;
              String markerPart = null;

              int markerIndex = line.indexOf(command.marker);
              if (markerIndex == 0) {
                contentPart = null;
                markerPart = line;
              } else if (markerIndex > 0) {
                contentPart = line.substring(0, markerIndex);
                markerPart = line.substring(markerIndex);
              }

              if (contentPart != null) {
                addBuffer(contentPart);
                processLine(contentPart, onStdoutLineListener);
                processLine(contentPart, command.onCommandLineListener);
              }

              if (markerPart != null) {
                try {
                  lastExitCode = Integer.valueOf(markerPart.substring(command.marker.length() + 1), 10);
                } catch (Exception e) {
                  // this really shouldn't happen
                  e.printStackTrace();
                }
                lastMarkerStdout = command.marker;
                processMarker();
              }
            }
          }
        });
        stderr = new StreamGobbler(process.getErrorStream(), new StreamGobbler.OnLineListener() {

          @Override
          public void onLine(String line) {
            synchronized (Interactive.this) {
              if (command == null) {
                return;
              }

              String contentPart = line;

              int markerIndex = line.indexOf(command.marker);
              if (markerIndex == 0) {
                contentPart = null;
              } else if (markerIndex > 0) {
                contentPart = line.substring(0, markerIndex);
              }

              if (contentPart != null) {
                if (wantSTDERR)
                  addBuffer(contentPart);
                processLine(contentPart, onStderrLineListener);
              }

              if (markerIndex >= 0) {
                lastMarkerStderr = command.marker;
                processMarker();
              }
            }
          }
        });

        // start gobbling and write our commands to the shell
        stdout.start();
        stderr.start();

        running = true;
        closed = false;

        runNextCommand();

        return true;
      } catch (IOException e) {
        // shell probably not found
        return false;
      }
    }
Internal call that launches the shell, starts gobbling, and starts executing commands. See
{@link Shell.Interactive}

@return Opened successfully ?
imitate/src/main/java/com/engineer/imitate/shell/Shell.java