Method: SshHelper::TmcSsh#send_command
- Defined in:
- lib/helpers/tmc_helpers/ssh_helper/ssh_helper.rb
#send_command(cmd, prompt: nil, expect: nil, timeout: 10.sec) ⇒ Object
Public: Sends a command to the session and waits for output.
cmd - String command to send. prompt - String or Regexp prompt to set for the current program (default: nil). expect - String or Regexp output to expect, if not the prompt (default: nil). timeout - Integer timeout in milliseconds (default: 10.sec).
Returns a String data buffered before the prompt or expected output.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/helpers/tmc_helpers/ssh_helper/ssh_helper.rb', line 88 def send_command(cmd, prompt: nil, expect: nil, timeout: 10.sec) if @pty.nil? # no active pty, just execute the command the normal way loginfo("Sending command: #{cmd}") output = @ssh.exec!(cmd) logdebug("Output:\n#{output.rstrip}") output else # send to active pty and wait send_raw(cmd + "\n") @pty_prompt = prompt unless prompt.nil? expect(expect, timeout: timeout) end end |