termconsole.go 799 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package execdriver
  2. import (
  3. "io"
  4. "os/exec"
  5. )
  6. type StdConsole struct {
  7. }
  8. func NewStdConsole(processConfig *ProcessConfig, pipes *Pipes) (*StdConsole, error) {
  9. std := &StdConsole{}
  10. if err := std.AttachPipes(&processConfig.Cmd, pipes); err != nil {
  11. return nil, err
  12. }
  13. return std, nil
  14. }
  15. func (s *StdConsole) AttachPipes(command *exec.Cmd, pipes *Pipes) error {
  16. command.Stdout = pipes.Stdout
  17. command.Stderr = pipes.Stderr
  18. if pipes.Stdin != nil {
  19. stdin, err := command.StdinPipe()
  20. if err != nil {
  21. return err
  22. }
  23. go func() {
  24. defer stdin.Close()
  25. io.Copy(stdin, pipes.Stdin)
  26. }()
  27. }
  28. return nil
  29. }
  30. func (s *StdConsole) Resize(h, w int) error {
  31. // we do not need to reside a non tty
  32. return nil
  33. }
  34. func (s *StdConsole) Close() error {
  35. // nothing to close here
  36. return nil
  37. }