通过exec.Command在控制台中工作

Please help. I have to pass the console commando with a certain number of parameters. There are many.

That is, ideally, should be as follows: test.go --distr For example: test.go --distr mc curl cron

i create function

 func chroot_create() {
        cmd := exec.Command("urpmi",
                "--urpmi-root",
                *fldir,
                "--no-verify-rpm",
                "--nolock",
                "--auto",
                "--ignoresize",
                "--no-suggests",
                "basesystem-minimal",
                "rpm-build",
                "sudo",
                "urpmi",
                "curl")
        if err := cmd.Run(); err != nil {
                log.Println(err)
        }
}

And catch parameter distr through flag.Parse ()

How do I get rid of "rpm-build", "sudo", "urpmi", "curl") That would not be tied to count packets. Please forgive me for stupidity, I'm just starting to learn golang. Especially when there was a problem.

Full code http://pastebin.com/yeuKy8Cc

You are looking for the ... operator.

func lsElements(elems ...string) {
        cmd := exec.Command("ls", append([]string{"-l", "-h", "/root"}, elems...)...)
        if err := cmd.Run(); err != nil {
                log.Println(err)
        }
}

You receive as function parameter ...string which is in really a []string, except that when you call the function, you pass the strings separately.

In order to use it, (and it works with any slices), you can "transform" your slice into list of element with ... suffix.

In the case of exec, you could use elem... directly if you had only this. However, has you have fixed parameters as well, you need to build your slice with append and extend it back with ...

Example: http://play.golang.org/p/180roQGL4a