Python เรียกใช้ Command line

การเรียกใช้ command line จาก Python สามารถเรียกได้โดยใช้คำสั่ง popen
import os
ipFile = “ip.txt”
opFile = “op.txt”
cmd = ‘swath <%s> %s’ % (ipFile, opFile)
f = os.popen(cmd)

หรือใช้ Popen
import subprocess
subprocess.Popen([r”gzip”,”-d”, “x.txt.gz”]).wait()

ที่มา: Subprocess managementMaking System Calls in Perl and Python