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

  • JorteexHD

    JorteexHD

    20 NİSAN 2012
  • уσ ρℓz sυв ιℓℓ sυв вαcқ

    уσ ρℓz

    14 EKİM 2010
  • Study with Substance P

    Study with S

    31 Mayıs 2008