mirror of
https://github.com/creack/pty.git
synced 2026-04-01 02:57:06 +09:00
27 lines
468 B
Go
27 lines
468 B
Go
package pty
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
// 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
|
|
err = c.Start()
|
|
if err != nil {
|
|
pty.Close()
|
|
return nil, err
|
|
}
|
|
return pty, err
|
|
}
|