(cmd string)
| 105 | } |
| 106 | |
| 107 | func (t *TelnetSession) Exec(cmd string) ([]byte, error) { |
| 108 | t.Lock() |
| 109 | defer t.Unlock() |
| 110 | |
| 111 | cmd = fmt.Sprintf("(%s || echo) && echo PLACEHOLDER", cmd) |
| 112 | if _, err := t.doWrite([]byte(cmd + "\n")); err != nil { |
| 113 | return nil, fmt.Errorf("error while sending telnet command: %s", err) |
| 114 | } |
| 115 | t.doReadUntil(cmd) |
| 116 | |
| 117 | if err, s := t.doReadUntil("PLACEHOLDER"); err != nil { |
| 118 | return nil, err |
| 119 | } else { |
| 120 | s = strings.Replace(s, "PLACEHOLDER", "", -1) |
| 121 | s = str.TrimLeft(s) |
| 122 | return []byte(s), nil |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func (t *TelnetSession) Close() { |
| 127 | t.Lock() |
nothing calls this directly
no test coverage detected