simpleexec

package module
v0.0.0-...-3f978aa Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2017 License: MIT Imports: 5 Imported by: 2

README

go-simpleexec

Wrapper around os/exec allowing easy piping of commands

Install

go get -u github.com/gurupras/go-simpleexec

Usage

package main

import (
        "bytes"
        "fmt"
        "strings"

        "github.com/gurupras/simple-exec"
)                                                               

func main() {
        buf := bytes.NewBuffer(nil)                             

        cmd := simpleexec.ParseCmd("man df").Pipe("grep inode").Pipe("wc -l").Pipe(`sed -e 's/2/4/g'`)
        cmd.Stdout = buf                                        

        cmd.Start()                                             
        cmd.Wait()                                              

        fmt.Printf("Found %v lines containing the word inode\n", strings.TrimSpace(buf.String()))
}

Found 4 lines containing the word inode

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Parent *Cmd
	*exec.Cmd
}

func ParseCmd

func ParseCmd(command string) *Cmd

func (*Cmd) Pipe

func (cmd *Cmd) Pipe(command string) *Cmd

func (*Cmd) Start

func (cmd *Cmd) Start() (err error)

func (*Cmd) Wait

func (cmd *Cmd) Wait() (err error)

The logic in this function is not perfect We probably need to handle parent errors and child errors separately

Jump to

Keyboard shortcuts

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