How to get the current CPU usage and available memory in batch file?

后端 未结 4 1316
盖世英雄少女心
盖世英雄少女心 2021-02-06 04:17

I am creating a simple script that outputs the current user logged in, CPU usage for the current system and the available memory?

I have managed to get the current user/

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 04:34

    Firstly, when running from a batch file, the for loop variable needs two percentage symbols - %%p

    Secondly, you need to echo %%p, not %p%:

    for /f "skip=1" %%p in ('wmic cpu get loadpercentage') do echo %%p
    

    From the command line:

    for /f "skip=1" %p in ('wmic cpu get loadpercentage') do echo %p
    

提交回复
热议问题