SORU
18 EYLÜL 2008, PERŞEMBE


Python harici bir komut arıyorum

Nasıl bir Python betiği içinde dış komut kabuk veya Windows Unix komut istemine yazılan olsaydım gibi) diyebilir miyim?

CEVAP
18 EYLÜL 2008, PERŞEMBE


Bu stdlib: subprocess module bak

from subprocess import call
call(["ls", "-l"])

Alt süreci avantajı vs sistemi daha esnek (stdout, stderr, "" durum kodu, daha iyi hata işleme, vb.) gerçek. o kadar azdır Os bence.sistem, çok önerilmiyor, ya olacak:

https://docs.python.org/2/library/subprocess.html#replacing-older-functions-with-the-subprocess-module

Hızlı/kirli/bir kez komut, os.system yeterli ama.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Glyn Dewis

    Glyn Dewis

    25 AĞUSTOS 2007
  • Marina and The Diamonds

    Marina and T

    8 Temmuz 2008
  • Videojug

    Videojug

    25 EKİM 2006