Created
October 24, 2013 22:48
-
-
Save rothwerx/7146476 to your computer and use it in GitHub Desktop.
Go: Small example of running system commands
This file contains 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 "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