I'm trying to get a list of processes including their current load. typeperf "\Process(*)\% Processor Time" -sc 1
seems to give me the output I want. Executing this from cmd
works.
Now I try to call that command from my Go code
// Command to list processes
cmdPS := exec.Command("typeperf", "\"\\Process(*)\\% Processor Time\"", "-sc", "1")
cmdPS.Stdout = &buff
cmdPS.Stderr = &errBuff
err := cmdPS.Run()
if err != nil {
log.Printf("Err: %s", buff.String())
return nil, errors.Wrapf(err, "Failed to call: ps ax -o")
}
This results in:
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.
Is the way I format the command string wrong? I would expect that executing this command directly and through Go it would run with the same permissions.
Looks like you need to remove the escaped quotes. The shell (or the cmd in this case) will handle the arguments for you.
However, running typeperf "\Process(*)\% Processor Time" -sc 1
yeilds to the following on my machine.
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.