lolamontes69

Python / Execute bash commands and print output to stdout.

Jun 3rd, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. import subprocess
  2.  
  3. def execute_unix(inputcommand):
  4.     p = subprocess.Popen(inputcommand, stdout=subprocess.PIPE, shell=True)
  5.     (output, err) = p.communicate()
  6.     return output
  7.  
  8. if __name__ == "__main__":
  9.     print "Welcome to PYSH version 1.0\n"
  10.     loopy = 0
  11.     while loopy == 0:
  12.         inputcommand = str(raw_input('pysh-1.0a$ '))
  13.         if inputcommand == "quit":
  14.             loopy = 1
  15.             continue
  16.         print execute_unix(inputcommand)
Advertisement
Add Comment
Please, Sign In to add comment