system

system

// requires package os/exec

[code=golang]
func system(params ...interface{}) string {

    // First argument is command to execute (string)
    // Optional 2nd argument is bool true for windows (vs linux/mac)
    // Returns string, empty if no error, otherwise error string

    var cmd *exec.Cmd

    cmdstring := params[0].(string)
    windows := false

    if len(params) > 1 {    // boolean, windows, default false
        windows = params[1].(bool)
    }

    if (!windows) {
        cmd = exec.Command("/bin/sh", "-c", cmdstring)
    } else {
        cmd = exec.Command("cmd.exe", "/C", cmdstring)
    }
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    cmd.Stdin = os.Stdin
    err := cmd.Run()
    if (err == nil) {
        return ""
    } else {
        return err.Error()
    }
}
[/code]