Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2008 Doug Hellmann All rights reserved.
  5. #
  6. """
  7. """
  8.  
  9. __version__ = "$Id$"
  10. #end_pymotw_header
  11.  
  12. import cmd
  13. import subprocess
  14.  
  15. class ShellEnabled(cmd.Cmd):
  16.  
  17. last_output = ''
  18.  
  19. def do_shell(self, line):
  20. "Run a shell command"
  21. print "running shell command:", line
  22. sub_cmd = subprocess.Popen(line,
  23. shell=True,
  24. stdout=subprocess.PIPE)
  25. output = sub_cmd.communicate()[0]
  26. print output
  27. self.last_output = output
  28.  
  29. def do_echo(self, line):
  30. """Print the input, replacing '$out' with
  31. the output of the last shell command.
  32. """
  33. # Obviously not robust
  34. print line.replace('$out', self.last_output)
  35.  
  36. def do_EOF(self, line):
  37. return True
  38.  
  39. if __name__ == '__main__':
  40. ShellEnabled().cmdloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement