🎌Komut Çalıştırma

Python üzerinde işletim sistemi komutlarını çalıştırma

🧆 Komutların çalıştırılması

Komutlar ve programların yönetimi subprocess paketi ile gerçekleşmektedir.

import subprocess, os

os.chdir(os.path.dirname(__file__)) # İstenilen dizine girme

# Orjinal komut: git descript --always
print(subprocess.check_output(["git", "describe", "--always"]).strip().decode()) 

🎪 Programların Çalıştırılması ve Çıktılarının Okunması

#!/usr/bin/env python3
from subprocess import Popen, PIPE

with Popen(r'C:\path\to\program.exe "arg 1" "arg 2"',
           stdout=PIPE, stderr=PIPE) as p:
    output, errors = p.communicate()
lines = output.decode('utf-8').splitlines()

🔗 Faydalı Bağlantılar

Last updated

© 2024 ~ Yunus Emre Ak ~ yEmreAk