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

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

從 Go 代碼調用 typeperf 以接收系統信息

從 Go 代碼調用 typeperf 以接收系統信息

Go
郎朗坤 2023-04-24 16:28:08
我正在嘗試獲取進程列表,包括它們的當前負載。 typeperf "\Process(*)\% Processor Time" -sc 1似乎給了我想要的輸出。從作品中執行cmd?,F在我嘗試從我的 Go 代碼中調用該命令// Command to list processescmdPS := exec.Command("typeperf", "\"\\Process(*)\\% Processor Time\"", "-sc", "1")cmdPS.Stdout = &buffcmdPS.Stderr = &errBufferr := cmdPS.Run()if err != nil {    log.Printf("Err: %s", buff.String())    return nil, errors.Wrapf(err, "Failed to call: ps ax -o")}這導致:Exiting, please wait...Error: No valid counters.Note:  In order to use typeperf, you must either be a member of the local  Performance Log Users group, or the command must be executed from an  elevated command window.我格式化命令字符串的方式有誤嗎?我希望直接執行此命令并通過 Go 執行它會以相同的權限運行。
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

看起來您需要刪除轉義引號。shell(或本例中的 cmd)將為您處理參數。

但是,typeperf "\Process(*)\% Processor Time" -sc 1 在我的機器上運行以下結果。

Error: No valid counters.

Note:
  In order to use typeperf, you must either be a member of the local
  Performance Log Users group, or the command must be executed from an
  elevated command window.


查看完整回答
反對 回復 2023-04-24
  • 1 回答
  • 0 關注
  • 241 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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