我正在尝试获取系统驱动器的信息。我面临的问题是如何将信息拆分并放到需要的地方。如果有多个卷,下面是所需的输出:
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)
驱动器
variable
正在迭代strdrives
的内容。但是,在循环中,使用独立变量(mount, osvol, guid
)如果strdrives中有多个条目,则预期结果将是重复的文本块 =>
相关问题 更多 >
编程相关推荐