我已经做了很多谷歌搜索,甚至看过stackoverflow,并尝试了一些我在这里找到的东西,但到目前为止没有任何作用。 我想收集我正在运行的Windows系统的所有磁盘和分区信息。像这样......
from subprocess import Popen, PIPE, STDOUT
p = None
def ReadToEndOfStdOut():
global p
if p:
<WHAT GOES HERE>
p = Popen(['diskpart'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
lines = ReadToEndOfStdOut()
p.stdin.write('list disk\n')
lines = ReadToEndOfStdOut()
disks = <# of disks listed in lines>
for disk in range(disks):
p.stdin.write('select disk {0}\n'.format(disk))
lines = ReadToEndOfStdOut()
p.stdin.write('detail disk\n')
lines = ReadToEndOfStdOut()
<parse disk information from lines>
p.stdin.write('list partition\n')
lines = ReadToEndOfStdOut()
partitions = <# of partitions listed in lines>
for partition in range(partitions)
p.stdin.write('select partition {0}\n'.format(partiton))
lines = ReadToEndOfStdOut()
p.stdin.write('detail partition\n')
lines = ReadToEndOfStdOut()
<parse partition information from lines>
p.stdin.write('exit')
lines = ReadToEndOfStdOut()
非常感谢任何帮助。