command

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

command

exec-based command tools.

Installation

Run the following command under your project:

go get -u github.com/NICEXAI/command

Basic Usage

If I want to execute the following command:

go build -o ./example/example.exe ./example/example.go

you can:

    if cmd, err := command.Run("go", "build", "-o", "./example/example.exe", "./example/example.go"); err != nil {
        log.Printf("command exec failed, error: %v", err)
        return
    }

    cmd.Wait()
    log.Printf("command exec success, error: %v", err)

If you want to stop the currently executing command, you can use cmd.Stop(), for example:

    cmd, err = command.Run("./example/example.exe")
    if err != nil {
        log.Printf("command exec failed, error: %v", err)
        return
    }

    go func() {
        time.Sleep(10 * time.Second)
        log.Println("process begins to exit")
        cmd.Stop()
    }()

    cmd.Wait()
    log.Printf("process exit success, error: %v", err)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

Cmd represents an external command being prepared or run

func Run

func Run(name string, arg ...string) (*Cmd, error)

Run that can output logs

func (*Cmd) Stop

func (c *Cmd) Stop() 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