Created
March 23, 2014 23:58
-
-
Save ShawnMilo/9731754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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