Created
April 29, 2024 22:39
-
-
Save MuhammetOzturk/ad145d1dff03e41965dd1d0e1e1459bb to your computer and use it in GitHub Desktop.
fdisk komutunu python ile kullanma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen,PIPE | |
fdiskl = "fdisk -l /home/muhammet/DietPi_RPi-ARMv8-Bookworm.img" | |
#fdisk -l 8. satirdan itaberen bolum bilgilerini verir. | |
device_info = Popen(fdiskl , stdout = PIPE, text = True, shell = True).stdout.read().splitlines()[8:] | |
#Sadece sektor bilgilerini elde ettikten sonra veriyi liste tipinde stringe cevir | |
device_info = '\n'.join(device_info) | |
#Yeni bir PIPE nesne olustur | |
pipe = Popen(f"echo \"{device_info}\"", stdout = PIPE, text = True, shell = True) | |
result = Popen("awk '{printf(\"%s\\n%s\\n\", $3,$4)}'", stdout = PIPE,stdin = pipe.stdout, text =True, shell = True) | |
print(result.stdout.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment