Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32006
| References | <508759A9.7070601@wisc.edu> <50875A83.6030806@wisc.edu> <50876356.3030005@wisc.edu> <CA+vVgJWV3hNxy8pM6JC4hc=yPtOY4XLUQFww7pE3=cYajaUJUQ@mail.gmail.com> |
|---|---|
| Date | 2012-10-24 02:33 -0400 |
| Subject | Re: The pty module, reading from a pty, and Python 2/3 |
| From | David Hutto <dwightdhutto@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2729.1351060428.27098.python-list@python.org> (permalink) |
import sys
import pty
import os
def get_text(filename):
#you need to find the file size, and place it as an integer in read
below, where you return the value
statinfo = os.stat(filename)
try:
( child_pid, fd ) = pty.fork() # OK
except OSError as e:
print(str(e))
sys.exit(1)
if child_pid == 0:
try:
with open("log.txt", "w") as f:
f.write("about to execlp")
os.execlp("cat", "cat", filename)
except:
with open("log.txt", "w") as f:
f.write("could not spawn process")
print("Could not spawn")
sys.exit(1)
child_pty = os.fdopen(fd)
#you have to input into read, how many characters you want read in. if
you place a random integer in, it will read to that integer within the
file
return child_pty.read(statinfo.st_size)
if __name__ == "__main__":
print(get_text("my-pty-test.py"))
--
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: The pty module, reading from a pty, and Python 2/3 David Hutto <dwightdhutto@gmail.com> - 2012-10-24 02:33 -0400
csiph-web