Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31985
| 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 | <edriscoll@wisc.edu> |
| 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; 'raised': 0.07; 'try:': 0.07; 'python': 0.09; '"w")': 0.09; '2to3': 0.09; 'filename)': 0.09; 'ioerror': 0.09; 'ioerror:': 0.09; 'oh,': 0.09; 'oserror': 0.09; 'spawn': 0.09; 'subject:module': 0.09; 'through,': 0.09; 'def': 0.10; ':-)': 0.13; '"about': 0.16; '(just': 0.16; '2.)': 0.16; '2.7.3': 0.16; '24,': 0.16; 'driscoll': 0.16; 'pty': 0.16; 'py3': 0.16; 'record,': 0.16; 'sys.exit(1)': 0.16; 'wrote:': 0.17; '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; 'pm,': 0.35; 'received:192.168.0': 0.35; 'except': 0.36; 'but': 0.36; 'child': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'subject:, ': 0.61; 'more': 0.63; 'subject:The': 0.71; 'information:': 0.74; '100%': 0.76; 'dumb': 0.84; 'quits.': 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 22:03:31 -0500 |
| From | Evan Driscoll <edriscoll@wisc.edu> |
| Subject | Re: The pty module, reading from a pty, and Python 2/3 |
| In-reply-to | <508759A9.7070601@wisc.edu> |
| To | python-list@python.org |
| X-Spam-Report | AuthenticatedSender=yes, SenderIP=192.168.0.3 |
| X-Spam-PmxInfo | Server=avs-15, Version=5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.10.24.25117, SenderIP=192.168.0.3 |
| References | <508759A9.7070601@wisc.edu> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2709.1351047773.27098.python-list@python.org> (permalink) |
| Lines | 71 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351047773 news.xs4all.nl 6941 [2001:888:2000:d::a6]:37157 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:31985 |
Show key headers only | View raw
Oh, and a little more information:
The log.txt file I create has the message that it's "about to execlp",
and the exec() *does* actually happen -- the IOError is raised after the
child process quits.
Evan
On 10/23/2012 09:59 PM, Evan Driscoll wrote:
> 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 <module>
> 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
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: The pty module, reading from a pty, and Python 2/3 Evan Driscoll <edriscoll@wisc.edu> - 2012-10-23 22:03 -0500
csiph-web