Skip to content

Instantly share code, notes, and snippets.

@rothwerx
Created October 24, 2013 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rothwerx/7146476 to your computer and use it in GitHub Desktop.
Save rothwerx/7146476 to your computer and use it in GitHub Desktop.
Go: Small example of running system commands
package main
import "os/exec"
import "fmt"
import "bytes"
func main() {
cmd := exec.Command("/bin/ls", "-al")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Run()
fmt.Println(out.String())
outs, err := exec.Command("date").Output()
if err != nil {
fmt.Println("Something went wrong")
}
fmt.Printf("The date is %s\n", outs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment