我正在尝试为我的系统驱动器提取信息。我遇到的问题是能够将信息拆分并放在需要的地方。如果有多个卷,以下是所需的输出:
Mountpoint: C:\
OS Volume: True
GUID: d1dd2893f42711e09090806e6f6e6963
Mountpoint: D:\
OS Volume: False
GUID: b4584ed2e3b211e2ae7d806e6f6e6963
以下是当我运行我目前拥有的内容时打印出来的信息:
Mountpoint: C:\
Mountpoint: D:\
OS Volume: True
OS Volume: False
GUID: d1dd2893f42711e09090806e6f6e6963
GUID: b4584ed2e3b211e2ae7d806e6f6e6963
我知道我做错了什么,我不知道如何解决它。我浏览了互联网无济于事。这可能只是我的天真。
这是我正在使用的代码:
def driveInfo(agent):
info = "info " + agent + " | grep "
drives = subprocess.Popen(info + "'\[mountpoints\]'", shell=True, stdout=subprocess.PIPE)
drives, err = drives.communicate()
strdrives = str(drives)
### Volume Information
mount = subprocess.Popen(info + "'\[mountpoints\]'", shell=True, stdout=subprocess.PIPE)
osvol = subprocess.Popen(info + "'\[OSVolume\]'", shell=True, stdout=subprocess.PIPE)
guid = subprocess.Popen(info + "'\[guid\]'", shell=True, stdout=subprocess.PIPE)
### Communicate calls
mount, err = mount.communicate()
osvol, err = osvol.communicate()
guid, err = guid.communicate()
### String conversions
mount = str(mount).strip()
osvol = str(osvol).strip()
guid = str(guid).strip()
### Drive Information Output
for drive in strdrives:
print mount
print osvol
print guid
driveInfo(agent)