I was figuring out
exec.Command()
In Go. It is straightforward and has no problem using primary terminal commands like "ls", "cat", etc...
But, when I wanted to use the output of the "log" command in macOS. It always returns an error.
Here is the simple usage of it:
func main() {
out, err := exec.Command("log", "help").Output()
if err != nil {
log.Printf("error: %v", err)
}
fmt.Println(string(out))
}
And here is the error:
2022/11/19 20:03:37 error: exit status 64
I expected to see outputs of log help
in macOS.
But, my program returns an error with exit status 64
Please let me know if there is anything I missed.
CodePudding user response:
There's nothing wrong with your code, if you try the exact same command you're executing in terminal, and see the exit status, it will be 64
:
➜ ~ log help
usage:
log <command>
global options:
-?, --help
-q, --quiet
-v, --verbose
commands:
collect gather system logs into a log archive
config view/change logging system settings
erase delete system logging data
show view/search system logs
stream watch live system logs
stats show system logging statistics
further help:
log help <command>
log help predicates
➜ ~ echo $?
64
And in case you're wondering why is it returning 64
, you can ask sysexits
for what it means:
➜ ~ man sysexits | grep -A 3 '64'
EX_USAGE (64) The command was used incorrectly, e.g., with the
wrong number of arguments, a bad flag, a bad syntax
in a parameter, or whatever.