Skip to content

Instantly share code, notes, and snippets.

@GivenZeng
Created December 11, 2017 08:29
Show Gist options
  • Save GivenZeng/bef26019798220cdc9259fd4a6cb0a9c to your computer and use it in GitHub Desktop.
Save GivenZeng/bef26019798220cdc9259fd4a6cb0a9c to your computer and use it in GitHub Desktop.
golang 运行shell脚本
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
)
func exec_shell(s string) {
cmd := exec.Command("/bin/bash", "-c", s)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", out.String())
}
func main() {
exec_shell("uname ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment