#Why is it when I run this os.Args Program am I getting a weird output

5 messages · Page 1 of 1 (latest)

drowsy grotto
#

Hi in running my simple OS.Args program its also outputting a weird file path with the output and I dont want that.

Here is my program:


import (
    "fmt"
    "os"
)

type candidate struct {
    name  string
    votes int
}

func main() {

    num_args := len(os.Args)
    if num_args < 2 {
        fmt.Println("Please enter more candidates")
    }

    const max = 9
    var candidate_count int
    candidate_count = num_args

    if candidate_count > max {
        fmt.Println("Maximum number of candidates is %i\n", max)
    }
    var candidates = new(candidate)
    for i := 0; i < len(os.Args); i++ {
        candidates.name = os.Args[i]
        fmt.Println(candidates.name)
    }

}```

Here is my output with the input: 

```jason@Jasons-MacBook-Air-2 GoLangProgForPularity % go run plurality.go jason sarah
/var/folders/3y/j5mlhwm52s9czwl1bt5c_4140000gn/T/go-build320798206/b001/exe/plurality
jason
sarah
karmic cairn
#

that weird filepath is path to the binary

drowsy grotto
#

what os args?

#

Why is it printing it out?

karmic cairn
#

os args is all argument thats passed to the binary, when you run it.
the first will always be either path to the binary or the command/executable name (if in PATH).