I'm currently trying to run a command from inside my Go program and parse an integer from the response. The command returns output like this:
6
fyb_src/ex1.fyb (1) wins!
Splitting the lines and removing the whitespace with strings.Split
and strings.TrimSpaces
works fine. However, while trying to parse the number into an integer I get the following error:
panic: strconv.ParseInt: parsing "0 1 2 3 4 5 6": invalid syntax
But printing the string I'm trying to parse to the terminal yields the following result:
6
I'm not really sure where to go from here. The number clearly looks like an integer to me. The error message isn't useful either (at least for me). Does anyone have an idea?
EDIT: The code I'm running
out, _ := exec.Command(pwd+"/osx_fukyobrane_amd64", "fyb_src/"+filename, "fyb_src/salty.fyb", "t").CombinedOutput()
parts := strings.Split(string(out), "
")
fmt.Println(parts[0])
rounds, err := strconv.Atoi(strings.TrimSpace(parts[0]))
if err != nil {
panic(err.Error())
}