Skip to content

Instantly share code, notes, and snippets.

@MuhammetOzturk
Created April 29, 2024 22:39
Show Gist options
  • Save MuhammetOzturk/ad145d1dff03e41965dd1d0e1e1459bb to your computer and use it in GitHub Desktop.
Save MuhammetOzturk/ad145d1dff03e41965dd1d0e1e1459bb to your computer and use it in GitHub Desktop.
fdisk komutunu python ile kullanma
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