Skip to content
/ execute Public

Convenience wrapper for GO's standard "exec" package that takes care of stdout, stderr and stdin, as well as resource limits (requires rlimiter to be installed in that case)

License

Notifications You must be signed in to change notification settings

ms-xy/execute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

execute

This is a convenience wrapper around the standard GO exec package.

It provides a somewhat elegant way to access stdout and stderr and feed data to stdin, without bothering the programmer with pipes and I/O.

There's little doubt that it can be optimized. It works fine, however, so there's little incentive to change anything for the better right now.

Usage

go get github.com/ms-xy/execute
import (
  "github.com/ms-xy/execute"
  "github.com/ms-xy/logtools"
)

func main() {
  logtools.Initialize()

  cmd := &execute.Command{
    LookupPath: true,
    WorkingDir: ".",

    Executable: "bash",
    Arguments:  []string{"-c", '"echo \"hello world\""'},
    Input:      []byte{},

    RlimitArgs: []string{}, // see github.com/ms-xy/rlimiter
    Timeout:    10*time.Second,
    StdoutSize: 10000, // size in bytes
    StderrSize: 10000, // size in bytes
  }

  if result, err := execute.Execute(cmd); err != nil {
    logtools.Errorf("Error happened while executing command: %+v", err)
  } else {
    logtools.Infof("Stdout of command: %s", string(result.Stdout))
  }
}

struct Command

type Command struct {
  LookupPath bool
  Executable string
  WorkingDir string
  Input      []byte
  RlimitArgs []string
  Arguments  []string
  Timeout    time.Duration
  StdoutSize int
  StderrSize int
}

struct ExecResult

type ExecResult struct {
  Stdout     []byte
  Stderr     []byte
  ExitCode   int
  Error      string
  ModTime    time.Time
  Killed     bool
  KillReason string
}

License

GNU GPLv3. Please see the attached License.txt file for details. Different license terms can be arranged on request.

About

Convenience wrapper for GO's standard "exec" package that takes care of stdout, stderr and stdin, as well as resource limits (requires rlimiter to be installed in that case)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages