File: ssh_windows.go

package info (click to toggle)
podman 5.4.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,124 kB
  • sloc: sh: 6,119; perl: 2,710; python: 2,258; ansic: 1,556; makefile: 1,022; xml: 121; ruby: 42; awk: 12; csh: 8
file content (42 lines) | stat: -rw-r--r-- 874 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package machine

import (
	"io"
	"os"
	"os/exec"

	"github.com/sirupsen/logrus"
)

func setupIOPassthrough(cmd *exec.Cmd, interactive bool, stdin io.Reader) error {
	cmd.Stdin = stdin

	if interactive {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		return nil
	}

	// OpenSSh mucks with the associated virtual console when there is no pty,
	// leaving it in a broken state. Pipe the output to isolate stdout/stderr
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return err
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return err
	}

	copier := func(name string, dest string, from io.Reader, to io.Writer) {
		if _, err := io.Copy(to, from); err != nil {
			logrus.Warnf("could not copy output from command %s to %s", name, dest)
		}
	}

	go copier(cmd.Path, "stdout", stdout, os.Stdout)
	go copier(cmd.Path, "stderr", stderr, os.Stderr)

	return nil
}