Go exec.Command() 返回退出状态 64

我想明白了


执行命令()


在去。它很简单,使用“ls”、“cat”等主要终端命令也没有问题……


但是,当我想在 macOS 中使用“log”命令的输出时。它总是返回一个错误。


这是它的简单用法:


func main() {

    out, err := exec.Command("log", "help").Output()

    if err != nil {

        log.Printf("error: %v", err)

    }


    fmt.Println(string(out))

}

这是错误:


2022/11/19 20:03:37 error: exit status 64


我希望在 macOS 中看到输出log help。


但是,我的程序返回错误exit status 64


如果我遗漏了什么,请告诉我。


Qyouu
浏览 79回答 1
1回答

千巷猫影

您的代码没有任何问题,如果您尝试在终端中执行完全相同的命令,并查看退出状态,它将是64:➜&nbsp; ~ log helpusage:&nbsp; &nbsp; log <command>global options:&nbsp; &nbsp; -?, --help&nbsp; &nbsp; -q, --quiet&nbsp; &nbsp; -v, --verbosecommands:&nbsp; &nbsp; collect&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gather system logs into a log archive&nbsp; &nbsp; config&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view/change logging system settings&nbsp; &nbsp; erase&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete system logging data&nbsp; &nbsp; show&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view/search system logs&nbsp; &nbsp; stream&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; watch live system logs&nbsp; &nbsp; stats&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;show system logging statisticsfurther help:&nbsp; &nbsp; log help <command>&nbsp; &nbsp; log help predicates➜&nbsp; ~ echo $?64如果您想知道它为什么返回64,您可以询问sysexits它的含义:➜&nbsp; ~ man sysexits | grep -A 3 '64'&nbsp; &nbsp; &nbsp;EX_USAGE (64)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;The command was used incorrectly, e.g., with the&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wrong number of arguments, a bad flag, a bad syntax&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in a parameter, or whatever.
打开App,查看更多内容
随时随地看视频慕课网APP