Created
February 20, 2014 07:16
-
-
Save jouyouyun/9108485 to your computer and use it in GitHub Desktop.
Test Command 'useradd'
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" | |
"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