I want to display in a browser the load percentage of a cpu trough php.
This is the code I am using:
$command ="C:\\wmic cpu get loadpercentage";
echo shell_exec("$command 2>&1 ; echo $?" );
'C:\wmic' is not recognized as an internal or external command, operable program or batch file.
$command ="C:\\wmic^ cpu^ get^ loadpercentage";
'C:\wmic cpu get loadpercentage' is not recognized as an internal or external command, operable program or batch file.
You have two problems, both of which we explored in the comments above:
The actual WMIC binary is located at
C:\wmic. That path needs to be used in your PHP command.
You are trying to use Unix-style shell concepts (redirecting
STDOUT, chaining commands with
;, and using
$?) on a Windows system.
Simply running the command without all that stuff should work:
echo shell_exec("C:\\Windows\\System32\\wbem\\WMIC.exe cpu get loadpercentage");