When I run a go program from the shell, os.Args[0] is the program name. If I invoke the same program using go's exec then os.Args[0] is not the program name, rather its the first argument that I pass.
Here is a simple program to show this behavior, installed as gocmd in my $GOPATH/bin func main() { fmt.Println(os.Args) if os.Args[0] == "self" { return } cmd := &exec.Cmd{ Path: <path to the program in $GOPATH/bin>, Args: []string{"self", "selftest"}, Stdout: os.Stdout, Stderr: os.Stderr, } if err := cmd.Run(); err != nil { fmt.Println("Run failed..", err) } } $ gocmd test1 test2 [gocmd test1 test2] [self selftest] $ Isn't the args[0] being the program name a behavior of exec call in Linux ? What is the reason for this difference only for the binaries executed by the exec package ? thanks, Santhosh. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.