Debian Codegraph @

xpty/conpty_windows.go

raw
1 //go:build windows
2 // +build windows
3
4 package xpty
5
6 import (
7 "fmt"
8 "os"
9 "os/exec"
10 "syscall"
11
12 "golang.org/x/sys/windows"
13 )
14
15 func (c *ConPty) start(cmd *exec.Cmd) error {
16 pid, proc, err := c.ConPty.Spawn(cmd.Path, cmd.Args, &syscall.ProcAttr{
17 Dir: cmd.Dir,
18 Env: cmd.Env,
19 Sys: cmd.SysProcAttr,
20 })
21 if err != nil {
22 return err //nolint:wrapcheck
23 }
24
25 cmd.Process, err = os.FindProcess(pid)
26 if err != nil {
27 // If we can't find the process via os.FindProcess, terminate the
28 // process as that's what we rely on for all further operations on the
29 // object.
30 if tErr := windows.TerminateProcess(windows.Handle(proc), 1); tErr != nil {
31 return fmt.Errorf("failed to terminate process after process not found: %w", tErr)
32 }
33 return fmt.Errorf("failed to find process after starting: %w", err)
34 }
35
36 return nil
37 }