Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ShawnMilo
Created March 23, 2014 23:58
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 ShawnMilo/9731754 to your computer and use it in GitHub Desktop.
Save ShawnMilo/9731754 to your computer and use it in GitHub Desktop.
package main
import (
"fmt" // for printing
"os/exec" // for executing system commands
)
func main() {
// exec.Command() is a function that returns a
// command that can be run in different ways, such as
// Output(), which returns the output, or Start(), which
// runs it but doesn't wait for it to complete. It requires
// at least the first argument, which is the command to be run.
// Many other options can be passed, including flags.
cmd := exec.Command("ls")
// run the command
out, err := cmd.Output()
if err != nil {
fmt.Printf("error: %s", err)
} else {
fmt.Printf("%s", out)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment