我正在嘗試獲取進程列表,包括它們的當(dāng)前負載。 typeperf "\Process(*)\% Processor Time" -sc 1似乎給了我想要的輸出。從作品中執(zhí)行cmd?,F(xiàn)在我嘗試從我的 Go 代碼中調(diào)用該命令// 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")}這導(dǎ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.我格式化命令字符串的方式有誤嗎?我希望直接執(zhí)行此命令并通過 Go 執(zhí)行它會以相同的權(quán)限運行。
1 回答
慕婉清6462132
TA貢獻1804條經(jīng)驗 獲得超2個贊
看起來您需要刪除轉(zhuǎn)義引號。shell(或本例中的 cmd)將為您處理參數(shù)。
但是,typeperf "\Process(*)\% Processor Time" -sc 1 在我的機器上運行以下結(jié)果。
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.
- 1 回答
- 0 關(guān)注
- 274 瀏覽
添加回答
舉報
0/150
提交
取消
