Python System Calls

From Wiki
Revision as of 22:30, 1 February 2011 by Scott (talk | contribs) (Created page with '== Backquotes == <source lang="python"> output = `dmesg | grep hda` </source> == os.popen == <source lang="python"> import os cmd = "medcon -f %s" % fileName output = os.popen(c…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Backquotes

output = `dmesg | grep hda`

os.popen

import os
cmd = "medcon -f %s" % fileName
output = os.popen(cmd)
for line in output:
    #do something with line

subprocess module (Python 2.4+)

from subprocess import *
cmd = "medcon -f %s" % fileName
output = Popen(cmd, shell=True, bufsize=512, stdout=PIPE).stdout
for line in output:
    #do something with line

The os.shutil module

Used for copying, moving, and deleting files and directories:

os.listdir(path)