go - Working in the console via exec.Command -



go - Working in the console via exec.Command -

please help. have pass console commando number of parameters. there many.

that is, ideally, should follows: test.go --distr 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 grab parameter distr through flag.parse ()

how rid of "rpm-build", "sudo", "urpmi", "curl") not tied count packets. please forgive me stupidity, i'm starting larn golang. when there problem.

full code http://pastebin.com/yeuky8cc

you looking ... 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 function parameter ...string in []string, except when phone call function, pass strings separately.

in order utilize it, (and works slices), can "transform" piece list of element ... suffix.

in case of exec, utilize elem... straight if had this. however, has have fixed parameters well, need build piece append , extend ...

example: http://play.golang.org/p/180roqgl4a

go console

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -