2014-02-24 15:28:45 -05:00
|
|
|
package execdriver
|
2014-02-21 15:32:14 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2014-02-22 04:21:26 -05:00
|
|
|
"os/exec"
|
2014-02-21 15:32:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type StdConsole struct {
|
|
|
|
}
|
|
|
|
|
2014-08-26 18:05:37 -04:00
|
|
|
func NewStdConsole(processConfig *ProcessConfig, pipes *Pipes) (*StdConsole, error) {
|
2014-02-21 15:42:37 -05:00
|
|
|
std := &StdConsole{}
|
|
|
|
|
2014-08-26 18:05:37 -04:00
|
|
|
if err := std.AttachPipes(&processConfig.Cmd, pipes); err != nil {
|
2014-02-21 15:42:37 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return std, nil
|
2014-02-21 15:32:14 -05:00
|
|
|
}
|
|
|
|
|
2014-02-26 15:55:24 -05:00
|
|
|
func (s *StdConsole) AttachPipes(command *exec.Cmd, pipes *Pipes) error {
|
2014-02-21 15:42:37 -05:00
|
|
|
command.Stdout = pipes.Stdout
|
|
|
|
command.Stderr = pipes.Stderr
|
2014-02-21 15:32:14 -05:00
|
|
|
|
|
|
|
if pipes.Stdin != nil {
|
2014-02-21 15:42:37 -05:00
|
|
|
stdin, err := command.StdinPipe()
|
2014-02-21 15:32:14 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer stdin.Close()
|
|
|
|
io.Copy(stdin, pipes.Stdin)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StdConsole) Resize(h, w int) error {
|
|
|
|
// we do not need to reside a non tty
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StdConsole) Close() error {
|
|
|
|
// nothing to close here
|
|
|
|
return nil
|
|
|
|
}
|