Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 616 Bytes

README.md

File metadata and controls

35 lines (26 loc) · 616 Bytes

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