亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號