Fragment Description:



The exec package in go proposes type 'Cmd' sign:
Command(name string, arg ...string) *Cmd This example uses the 'Output()' method sign:(c *Cmd) Output() ([]byte, error) Output runs the command and returns its standard output.


execCmdOutput

Go Playground

Last update, on 2015, Fri 9 Oct, 16:15:33

/* ... <== see fragment description ... */

package main

import (
    "fmt"
    "log"
    "os/exec"
)

func main() {
    out, err := exec.Command("ls").Output()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("The ls result is:\n%s", out)
}

/* Expected Output:
The ls result is:
output.exe
output.go
*/



Comments