private void shell()

in modules/ssh-ext/src/main/java/org/apache/ignite/internal/util/nodestart/StartNodeCallableImpl.java [341:397]


    private void shell(Session ses, String cmd, String regexp)
        throws JSchException, IOException, IgniteInterruptedCheckedException {
        ChannelShell ch = null;

        GridTimeoutObject to = null;

        try {
            ch = (ChannelShell)ses.openChannel("shell");

            ch.connect();

            try (PrintStream out = new PrintStream(ch.getOutputStream(), true)) {
                out.println(cmd);
            }

            if (regexp != null) {
                Pattern ptrn = Pattern.compile(regexp);

                try (BufferedReader reader = new BufferedReader(new InputStreamReader(ch.getInputStream()))) {
                    String line;

                    boolean first = true;

                    while ((line = reader.readLine()) != null) {
                        if (ptrn.matcher(line).find()) {
                            // Wait for a while until process from regexp really will be started.
                            U.sleep(50);

                            break;
                        }
                        else if (first) {
                            to = initTimer(cmd);

                            first = false;
                        }
                    }
                }
                catch (InterruptedIOException ignore) {
                    // No-op.
                }
                finally {
                    if (to != null) {
                        boolean r = proc.removeTimeoutObject(to);

                        assert r || to.endTime() <= U.currentTimeMillis() : "Timeout object was not removed: " + to;
                    }
                }

            }
            else
                U.sleep(EXECUTE_WAIT_TIME);
        }
        finally {
            if (ch != null && ch.isConnected())
                ch.disconnect();
        }
    }