Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Go exec.Command() returns exit status 64

I was figuring out

exec.Command()

In Go. It is straightforward and has no problem using primary terminal commands like "ls", "cat", etc…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading