Skip to content

Instantly share code, notes, and snippets.

@jouyouyun
Created February 20, 2014 07:16
Show Gist options
  • Save jouyouyun/9108485 to your computer and use it in GitHub Desktop.
Save jouyouyun/9108485 to your computer and use it in GitHub Desktop.
Test Command 'useradd'
package main
import (
"fmt"
"os/exec"
)
func main() {
args := []string{}
args = append(args, "-m")
args = append(args, "-s /bin/bash")
args = append(args, "-c Test")
args = append(args, "test")
execCommand("/usr/sbin/useradd", args)
}
func execCommand(cmdline string, args []string) {
bytes, err := exec.Command(cmdline, args...).Output()
if err != nil {
fmt.Println("Exec", cmdline, args, "failed:", err)
fmt.Println(string(bytes))
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment