Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import pty
  4. import os
  5.  
  6. def get_text(filename):
  7.     try:
  8.         ( child_pid, fd ) = pty.fork()    # OK
  9.     except OSError as e:
  10.         print(str(e))
  11.         sys.exit(1)
  12.  
  13.     if child_pid == 0:
  14.         try:
  15.             with open("log.txt", "w") as f:
  16.                 f.write("about to execlp")
  17.             os.execlp("cat", "cat", filename)
  18.         except:
  19.             with open("log.txt", "w") as f:
  20.                 f.write("could not spawn process")
  21.             print("Could not spawn")
  22.             sys.exit(1)
  23.  
  24.     child_pty = os.fdopen(fd)
  25.     return child_pty.read()
  26.    
  27.  
  28. if __name__ == "__main__":
  29.     print(get_text("my-pty-test.py"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement