Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: The pty module, reading from a pty, and Python 2/3

Reply
Thread Tools

Re: The pty module, reading from a pty, and Python 2/3

 
 
Evan Driscoll
Guest
Posts: n/a
 
      10-24-2012
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
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: The pty module, reading from a pty, and Python 2/3 David Hutto Python 0 10-24-2012 06:40 AM
Re: The pty module, reading from a pty, and Python 2/3 David Hutto Python 0 10-24-2012 06:33 AM
Re: The pty module, reading from a pty, and Python 2/3 David Hutto Python 0 10-24-2012 06:02 AM
Re: The pty module, reading from a pty, and Python 2/3 Evan Driscoll Python 0 10-24-2012 03:41 AM
The pty module, reading from a pty, and Python 2/3 Evan Driscoll Python 0 10-24-2012 02:59 AM



Advertisments