为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
Qyouu 2023-03-15 15:37:44
我想明白了执行命令()在去。它很简单,使用“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如果我遗漏了什么,请告诉我。
查看完整描述

1 回答

?
千巷猫影

TA贡献1829条经验 获得超7个赞

您的代码没有任何问题,如果您尝试在终端中执行完全相同的命令,并查看退出状态,它将是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

如果您想知道它为什么返回64,您可以询问sysexits它的含义:


➜  ~ 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.


查看完整回答
反对 回复 2023-03-15
  • 1 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信