import os
from subprocess import Popen, PIPE
os.system('mkdir c:\\temp\\vhd')
p = Popen(['diskpart'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
p.stdin.write(
    'create vdisk file=c:\\temp\\vhd\\test.vhd maximum=2000 type=expandable\n')
p.stdin.write('attach vdisk\n')
p.stdin.write('create partition primary size=10\n')
p.stdin.write('format fs=ntfs quick\n')
p.stdin.write('assign letter=r\n')
p.stdin.write('exit\n')
results, errors = p.communicate()
os.system('fsutil file createnew r:\\dummy.txt 6553600')
закрытие подпроцессов команды python