Python - emulando comandos shell

· 1min · Zero Andrade
#!/usr/bin/python
#-*- coding: UTF-8 -*-

import os

class Cmd(object):
   def __init__(self, cmd):
       self.cmd = cmd
   def __call__(self, *args):
       return os.system("%s %s" % (self.cmd, " ".join(args)))

class Sh(object):
    def __getattr__(self, attribute):
        return Cmd(attribute)

# exemplos de uso:

sh = Sh()
sh.ls('-la')
sh.free()
sh.ps('aux')
sh.uname('-a')