简体   繁体   中英

How to read an SD card's UUID?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM