File: process.go

package info (click to toggle)
golang-github-cloudflare-tableflip 1.2.1~git20200514.4baec98-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 196 kB
  • sloc: makefile: 2
file content (47 lines) | stat: -rw-r--r-- 827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package tableflip

import (
	"fmt"
	"os"
	"os/exec"
)

var initialWD, _ = os.Getwd()

type process interface {
	fmt.Stringer
	Signal(sig os.Signal) error
	Wait() error
}

type osProcess struct {
	cmd *exec.Cmd
}

func newOSProcess(executable string, args []string, files []*os.File, env []string) (process, error) {
	cmd := exec.Command(executable, args...)
	cmd.Dir = initialWD
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.ExtraFiles = files
	cmd.Env = env

	if err := cmd.Start(); err != nil {
		return nil, err
	}

	return &osProcess{cmd}, nil
}

func (osp *osProcess) Signal(sig os.Signal) error {
	return osp.cmd.Process.Signal(sig)
}

func (osp *osProcess) Wait() error {
	return osp.cmd.Wait()
}

func (osp *osProcess) String() string {
	return fmt.Sprintf("pid=%d", osp.cmd.Process.Pid)
}