Skip to content
exec.Command, but with logging
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
example_test.go
loggedexec.go
loggedexec_test.go
streams.go

README.md

exec.Command, but with logging

Will duplicate stdout and stderr into program log.

Example

logger := log.New(os.Stdout, `LOG: `, 0)

cmd := lexec.New(lexec.Loggerf(logger.Printf), `wc`, `-l`)

cmd.SetStdin(bytes.NewBufferString("1\n2\n3\n"))

err := cmd.Run()
if err != nil {
    log.Fatalln(karma.Format(
        err,
        `can't run example command`,
    ))
}

stdout, err := ioutil.ReadAll(cmd.GetStdout())
if err != nil {
    log.Fatalln(karma.Format(
        err,
        `can't read command stdout`,
    ))
}

fmt.Printf("OUT: %s\n", stdout)

// Output:
// LOG: <stdout> {wc} 3
// OUT: 3
You can’t perform that action at this time.