github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/daemon/execdriver/termconsole.go (about) 1 package execdriver 2 3 import ( 4 "io" 5 "os/exec" 6 ) 7 8 // StdConsole defines standard console operations for execdriver 9 type StdConsole struct { 10 } 11 12 // NewStdConsole returns a new StdConsole struct 13 func NewStdConsole(processConfig *ProcessConfig, pipes *Pipes) (*StdConsole, error) { 14 std := &StdConsole{} 15 16 if err := std.AttachPipes(&processConfig.Cmd, pipes); err != nil { 17 return nil, err 18 } 19 return std, nil 20 } 21 22 // AttachPipes attaches given pipes to exec.Cmd 23 func (s *StdConsole) AttachPipes(command *exec.Cmd, pipes *Pipes) error { 24 command.Stdout = pipes.Stdout 25 command.Stderr = pipes.Stderr 26 27 if pipes.Stdin != nil { 28 stdin, err := command.StdinPipe() 29 if err != nil { 30 return err 31 } 32 33 go func() { 34 defer stdin.Close() 35 io.Copy(stdin, pipes.Stdin) 36 }() 37 } 38 return nil 39 } 40 41 // Resize implements Resize method of Terminal interface 42 func (s *StdConsole) Resize(h, w int) error { 43 // we do not need to resize a non tty 44 return nil 45 } 46 47 // Close implements Close method of Terminal interface 48 func (s *StdConsole) Close() error { 49 // nothing to close here 50 return nil 51 }