Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # encoding: utf-8
- #
- # Copyright (c) 2008 Doug Hellmann All rights reserved.
- #
- """
- """
- __version__ = "$Id$"
- #end_pymotw_header
- import cmd
- import subprocess
- class ShellEnabled(cmd.Cmd):
- last_output = ''
- def do_shell(self, line):
- "Run a shell command"
- print "running shell command:", line
- sub_cmd = subprocess.Popen(line,
- shell=True,
- stdout=subprocess.PIPE)
- output = sub_cmd.communicate()[0]
- print output
- self.last_output = output
- def do_echo(self, line):
- """Print the input, replacing '$out' with
- the output of the last shell command.
- """
- # Obviously not robust
- print line.replace('$out', self.last_output)
- def do_EOF(self, line):
- return True
- if __name__ == '__main__':
- ShellEnabled().cmdloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement