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

  • Epic Tutorials for iPhone, iPad and iOS

    Epic Tutoria

    18 EYLÜL 2011
  • FattySpins's channel

    FattySpins's

    17 Mayıs 2009
  • Pepsi

    Pepsi

    1 Kasım 2005