mirror of
https://github.com/creack/pty.git
synced 2026-04-01 11:07:11 +09:00
Add StartWithSize to allow resizing pty before starting a command to avoid races (#62)
This commit is contained in:
committed by
Guillaume J. Charmes
parent
fa756f09ee
commit
db8e3cd836
16
run.go
16
run.go
@@ -12,11 +12,27 @@ import (
|
||||
// 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) {
|
||||
return StartWithSize(c, nil)
|
||||
}
|
||||
|
||||
// StartWithSize 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.
|
||||
//
|
||||
// This will resize the pty to the specified size before starting the command
|
||||
func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) {
|
||||
pty, tty, err := Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tty.Close()
|
||||
if sz != nil {
|
||||
err = Setsize(pty, sz)
|
||||
if err != nil {
|
||||
pty.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.Stdout = tty
|
||||
c.Stdin = tty
|
||||
c.Stderr = tty
|
||||
|
||||
Reference in New Issue
Block a user