For security reasons, I am not allowed to use any packages downloaded from pypi, including PSUTIL. Is there a way to be able to retrieve the CPU Usage and RAM Usage without it?
I believe there is already an existing question for this with a solution where I can read /proc/stat, but that is not an option for me, because I am using Windows server, not linux.
I was thinking maybe I can execute a "get CPU/RAM Usage" shell command and printing the output in Python using subprocess module, but I'm getting an error. Here is my code:
import subprocess
result = subprocess.run(['Get-WmiObject -Class Win32_Processor | Select LoadPercentage', '-l'], stdout=subprocess.PIPE)
result.stdout
I'm getting a "FileNotFoundError: [WinError 2] The system cannot find the file specified" error.
More detailed error message:
File "C:\Users\acer\Documents\Test.py", line 2, in <module>
result = subprocess.run(['Get-WmiObject -Class Win32_Processor | Select LoadPercentage', '-l'], stdout=subprocess.PIPE)
File "C:\Users\acer\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\acer\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\acer\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified