exec

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 10 Imported by: 0

README

exec

go pakcage exec 的封装

usage:

import (
    "context"
    "log"
    "strings"
    "gitee.com/go-wena/exec"
)

func main(){
    c := exec.New("SomeProc").Command("sleep", "10s")
    if err := c.Start(context.Background()); err != nil {
    	log.Fatal(err)
    }
    log.Println(c.PID)
    go func(){
    	time.Sleep(time.Second*3)
        if err := c.Terminate(); err != nil { //c.Interrupt()
            log.Println(err)
        }
    }()
    if err := c.Wait(); err != nil {
        log.Fatal(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Name       string   `yaml:"name"`
	Path       string   `yaml:"path"`
	Args       []string `yaml:"args"`
	Env        []string `yaml:"env"`
	Dir        string   `yaml:"dir"`
	Background bool     `yaml:"background"`
	PID        int      `yaml:"-"`
	// contains filtered or unexported fields
}

func New

func New(name string) *Cmd

func (*Cmd) Command

func (c *Cmd) Command(path string, args ...string) *Cmd

func (*Cmd) Interrupt

func (c *Cmd) Interrupt() (err error)

func (*Cmd) IsAlive

func (c *Cmd) IsAlive() bool

func (*Cmd) NoOut

func (c *Cmd) NoOut() *Cmd

func (*Cmd) OnCompleted

func (c *Cmd) OnCompleted(onCompleted func()) *Cmd

func (*Cmd) Run

func (c *Cmd) Run() error

func (*Cmd) SetBackground

func (c *Cmd) SetBackground(background ...bool) *Cmd

SetBackground usage: c.SetBackground() or c.SetBackground(false)

func (*Cmd) SetDIR

func (c *Cmd) SetDIR(dir string) *Cmd

func (*Cmd) SetEnv

func (c *Cmd) SetEnv(name, value string) *Cmd

func (*Cmd) Start

func (c *Cmd) Start(ctx context.Context) error

func (*Cmd) Terminate

func (c *Cmd) Terminate() (err error)

func (*Cmd) Wait

func (c *Cmd) Wait() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL