mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f2614f2107
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
28 lines
546 B
Go
28 lines
546 B
Go
package pty
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
// Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout,
|
|
// and c.Stderr, calls c.Start, and returns the File of the tty's
|
|
// corresponding pty.
|
|
func Start(c *exec.Cmd) (pty *os.File, err error) {
|
|
pty, tty, err := Open()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tty.Close()
|
|
c.Stdout = tty
|
|
c.Stdin = tty
|
|
c.Stderr = tty
|
|
c.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true}
|
|
err = c.Start()
|
|
if err != nil {
|
|
pty.Close()
|
|
return nil, err
|
|
}
|
|
return pty, err
|
|
}
|