I am trying to make a script to read an SD card's UUID, but I didn't find anything helpful. I know I can read it in the terminal with the command:
sudo blkid
But is there any way that I can read it through a Python script?
I am trying to make a script to read an SD card's UUID, but I didn't find anything helpful. I know I can read it in the terminal with the command:
sudo blkid
But is there any way that I can read it through a Python script?
This can be easily accomplished using the subprocess
library
import subprocess
command = "sudo blkid"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
print(output)
Giving you:
/dev/sdb1: LABEL="ESP" UUID="<UUID>" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="<PARTUUID>"
/dev/sdb3: UUID="<UUID>" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="<PARTUUID>"
Had to cover my UUID's just in case :)
Keep in mind that you will be asked for root privileges the first time you run the script through bash, but the second time will be smooth as needed, or just run it as root without sudo