Command (Environment) in Go

Posted by GoDoc
Public (Editable by Users)

Command returns the Cmd struct to execute the named program with the given arguments.

Go
Edit
package main

import (
	"log"
	"os"
	"os/exec"
)

func main() {
	cmd := exec.Command("prog")
	cmd.Env = append(os.Environ(),
		"FOO=duplicate_value", // ignored
		"FOO=actual_value",    // this value is used
	)
	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
}