简体   繁体   English

需要在 MacOS 中使用 ioreg 使用 Python 获取 USB 序列号吗?

[英]Need Use ioreg get USB Serial Number with Python in MacOS?

I try write a small script:我试着写一个小脚本:

import os
os.system("ioreg -p IOUSB -l -b | grep 'USB Serial Number'>> test.txt")

result receive in test.txt:结果在 test.txt 中接收:

"USB Serial Number" = "123456789101213131516"
"USB Serial Number" = "35432"
"USB Serial Number" = "0005663"

i want result receive in test.txt:我希望在 test.txt 中收到结果:

123456789101213131516
35432
0005663

I look forward to your support!我期待您的支持!

Check this.检查这个。

import os
string='"USB Serial Number" = "123456789101213131516"'
print (string.replace("\"","").split("=")[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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