go build -o ~/bin/test-2 test-2.go
$ go run main.go
bar a b
package main | |
import ( | |
"log" | |
"os" | |
"os/exec" | |
) | |
func main() { | |
if err := core(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func core() error { | |
cmd := exec.Command("test-2", "a", "b") | |
cmd.Args[0] = "bar" | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
if err := cmd.Run(); err != nil { | |
return err | |
} | |
return nil | |
} |
package main | |
import ( | |
"fmt" | |
"os" | |
"strings" | |
) | |
func main() { | |
fmt.Println(strings.Join(os.Args, " ")) | |
} |