Created
December 11, 2017 08:29
-
-
Save GivenZeng/bef26019798220cdc9259fd4a6cb0a9c to your computer and use it in GitHub Desktop.
golang 运行shell脚本
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 ( | |
"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