Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'importing': 0.04; 'subject:Python': 0.05; 'sys': 0.05; '"__main__":': 0.07; '__name__': 0.07; 'except:': 0.07; 'try:': 0.07; 'python': 0.09; '"w")': 0.09; '2to3': 0.09; 'filename)': 0.09; 'ioerror:': 0.09; 'oserror': 0.09; 'spawn': 0.09; 'subject:module': 0.09; 'through,': 0.09; 'def': 0.10; ':-)': 0.13; '(just': 0.16; '2.)': 0.16; '2.7.3': 0.16; '24,': 0.16; 'pty': 0.16; 'py3': 0.16; 'record,': 0.16; 'sys.exit(1)': 0.16; 'skip:p 30': 0.20; 'mostly': 0.20; 'import': 0.21; "i've": 0.23; 'linux': 0.24; 'header:User- Agent:1': 0.26; '(which': 0.26; '(most': 0.27; "doesn't": 0.28; 'subject:/': 0.28; 'run': 0.28; "i'm": 0.29; 'worked': 0.30; 'error': 0.30; 'file': 0.32; 'suggestion': 0.32; 'print': 0.32; 'rid': 0.33; 'traceback': 0.33; 'ubuntu': 0.33; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'received:192.168.0': 0.35; 'except': 0.36; 'but': 0.36; 'charset:us-ascii': 0.36; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'subject:, ': 0.61; 'subject:The': 0.71; '100%': 0.76; 'dumb': 0.84; 'received:192.168.0.3': 0.84; 'sunshine': 0.84; 'reducing': 0.95 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed Date: Tue, 23 Oct 2012 21:59:53 -0500 From: Evan Driscoll Subject: The pty module, reading from a pty, and Python 2/3 To: python-list@python.org X-Spam-Report: AuthenticatedSender=yes, SenderIP=192.168.0.3 X-Spam-PmxInfo: Server=avs-16, Version=5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.10.24.24514, SenderIP=192.168.0.3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351051154 news.xs4all.nl 6854 [2001:888:2000:d::a6]:36347 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31988 I have the following program. Everything is sunshine and rainbows when I run in in Python 2, but when I run it under Python 3 I get an IOError. 2to3 only reports one dumb suggestion re. a print call (which I can get rid of by importing __future__'s print_function, and then it just suggests removing that import). Can anyone shed any light? I am on Ubuntu Linux with Python 2.7.3 and 3.2.3. (Just for the record, I figured out that it ran under Python 2 by accident as I was reducing it for a "why doesn't this run?" email. :-) I'm not super-familiar with Py3 as I've mostly only worked with 2.) I'm not 100% sure how this will come through, so I've also put it at http://pastebin.com/60wjXSF3. Evan import sys import pty import os def get_text(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) return child_pty.read() if __name__ == "__main__": print(get_text("my-pty-test.py")) The read error I get is Traceback (most recent call last): File "my-pty-test.py", line 28, in print(get_text("my-pty-test.py")) File "my-pty-test.py", line 24, in get_text return child_pty.read() IOError: [Errno 5] Input/output error