Run command on remote machine and returns its stdout as a string
(command string, timeout ...time.Duration)
| 445 | |
| 446 | // Run command on remote machine and returns its stdout as a string |
| 447 | func (ssh_conf *MakeConfig) Run(command string, timeout ...time.Duration) (outStr string, errStr string, isTimeout bool, err error) { |
| 448 | stdoutChan, stderrChan, doneChan, errChan, err := ssh_conf.Stream(command, timeout...) |
| 449 | if err != nil { |
| 450 | // Check if the error is from a proxy dial timeout |
| 451 | if errors.Is(err, ErrProxyDialTimeout) { |
| 452 | isTimeout = true |
| 453 | } |
| 454 | return outStr, errStr, isTimeout, err |
| 455 | } |
| 456 | // read from the output channel until the done signal is passed |
| 457 | loop: |
| 458 | for { |
| 459 | select { |
| 460 | case isTimeout = <-doneChan: |
| 461 | break loop |
| 462 | case outline, ok := <-stdoutChan: |
| 463 | if !ok { |
| 464 | stdoutChan = nil |
| 465 | } |
| 466 | if outline != "" { |
| 467 | outStr += outline + "\n" |
| 468 | } |
| 469 | case errline, ok := <-stderrChan: |
| 470 | if !ok { |
| 471 | stderrChan = nil |
| 472 | } |
| 473 | if errline != "" { |
| 474 | errStr += errline + "\n" |
| 475 | } |
| 476 | case err = <-errChan: |
| 477 | } |
| 478 | } |
| 479 | // return the concatenation of all signals from the output channel |
| 480 | return outStr, errStr, isTimeout, err |
| 481 | } |
| 482 | |
| 483 | // WriteFile reads size bytes from the reader and writes them to a file on the remote machine |
| 484 | func (ssh_conf *MakeConfig) WriteFile(reader io.Reader, size int64, etargetFile string) error { |