start.go 670 B

12345678910111213141516171819202122232425
  1. //go:build !windows
  2. // +build !windows
  3. package pty
  4. import (
  5. "os"
  6. "os/exec"
  7. "syscall"
  8. )
  9. // StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout,
  10. // and c.Stderr, calls c.Start, and returns the File of the tty's
  11. // corresponding pty.
  12. //
  13. // This will resize the pty to the specified size before starting the command.
  14. // Starts the process in a new session and sets the controlling terminal.
  15. func StartWithSize(cmd *exec.Cmd, ws *Winsize) (*os.File, error) {
  16. if cmd.SysProcAttr == nil {
  17. cmd.SysProcAttr = &syscall.SysProcAttr{}
  18. }
  19. cmd.SysProcAttr.Setsid = true
  20. cmd.SysProcAttr.Setctty = true
  21. return StartWithAttrs(cmd, ws, cmd.SysProcAttr)
  22. }