I try to list connected USB devices in my Python project.
I tried to use os.system() with a command prompt but I cannot find a command for command prompt to list connected USB devices (names).
I found a PowerShell command which is
Get-PnpDevice -PresentOnly | Where-Object { $_. InstanceId -match '^USB' }
That works fine.
I want to know if there is either a command prompt to list USB connected devices with os.system() or how to run the PowerShell cmdlet in Python using os.system() or any other command.
>Solution :
There is a module called pyUSB that works really well.
Alternatively, to run Powershell commands, you can use the subprocess package.
import subprocess
result = subprocess.run(["powershell", "-Command", MyCommand], capture_output=True)