Exemple #1
0
func (t *TtyConsole) attach(command *execdriver.Command, pipes *execdriver.Pipes) error {
	command.Stdout = t.slave
	command.Stderr = t.slave
	command.Console = t.slave.Name()

	go func() {
		if wb, ok := pipes.Stdout.(interface {
			CloseWriters() error
		}); ok {
			defer wb.CloseWriters()
		}
		io.Copy(pipes.Stdout, t.master)
	}()

	if pipes.Stdin != nil {
		command.Stdin = t.slave
		command.SysProcAttr.Setctty = true

		go func() {
			defer pipes.Stdin.Close()
			io.Copy(t.master, pipes.Stdin)
		}()
	}
	return nil
}
Exemple #2
0
func (s *StdConsole) attach(command *execdriver.Command, pipes *execdriver.Pipes) error {
	command.Stdout = pipes.Stdout
	command.Stderr = pipes.Stderr

	if pipes.Stdin != nil {
		stdin, err := command.StdinPipe()
		if err != nil {
			return err
		}

		go func() {
			defer stdin.Close()
			io.Copy(stdin, pipes.Stdin)
		}()
	}
	return nil
}