Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

os.fdopen() issue in Python 3.1?

18 views
Skip to first unread message

Albert Hopkins

unread,
Mar 2, 2010, 9:24:58 AM3/2/10
to pytho...@python.org
I have a snippet of code that looks like this:

pid, fd = os.forkpty()
if pid == 0:
subprocess.call(args)
else:
input = os.fdopen(fd).read()
...


This seems to work find for CPython 2.5 and 2.6 on my Linux system.
However, with CPython 3.1 I get:

input = os.fdopen(fd).read()
IOError: [Errno 5] Input/output error

Is there something wrong in Python 3.1? Is this the correct way to do
this (run a process in a pseudo-tty and read it's output) or is there
another way I should/could be doing this?

-a


MRAB

unread,
Mar 2, 2010, 12:32:40 PM3/2/10
to pytho...@python.org
The documentation also mentions the 'pty' module. Have you tried that
instead?

Terry Reedy

unread,
Mar 2, 2010, 1:25:16 PM3/2/10
to pytho...@python.org
On 3/2/2010 9:24 AM, Albert Hopkins wrote:
> I have a snippet of code that looks like this:
>
> pid, fd = os.forkpty()
> if pid == 0:
> subprocess.call(args)
> else:
> input = os.fdopen(fd).read()
> ...
>
>
> This seems to work find for CPython 2.5 and 2.6 on my Linux system.

To get help, or report a bug, for something like this, be as specific as
possible. 'Linux' may be too generic.

> However, with CPython 3.1 I get:
>
> input = os.fdopen(fd).read()
> IOError: [Errno 5] Input/output error
>
> Is there something wrong in Python 3.1? Is this the correct way to do
> this (run a process in a pseudo-tty and read it's output) or is there
> another way I should/could be doing this?

No idea, however, the first thing I would do is call the .fdopen and
.read methods separately (on separate lines) to isolate which is raising
the error.

tjr

Albert Hopkins

unread,
Mar 2, 2010, 3:22:27 PM3/2/10
to pytho...@python.org
On Tue, 2010-03-02 at 13:25 -0500, Terry Reedy wrote:

> To get help, or report a bug, for something like this, be as specific as
> possible. 'Linux' may be too generic.

This is on Python on Gentoo Linux x64 with kernel 2.6.33.

>
> > However, with CPython 3.1 I get:
> >
> > input = os.fdopen(fd).read()
> > IOError: [Errno 5] Input/output error
> >
> > Is there something wrong in Python 3.1? Is this the correct way to do
> > this (run a process in a pseudo-tty and read it's output) or is there
> > another way I should/could be doing this?
>
> No idea, however, the first thing I would do is call the .fdopen and
> .read methods separately (on separate lines) to isolate which is raising
> the error.

The exception occurs on the read() method.


Albert Hopkins

unread,
Mar 2, 2010, 3:22:58 PM3/2/10
to pytho...@python.org
On Tue, 2010-03-02 at 17:32 +0000, MRAB wrote:
> The documentation also mentions the 'pty' module. Have you tried that
> instead?

I haven't but I'll give it a try. Thanks.

-a


Albert Hopkins

unread,
Mar 2, 2010, 6:45:49 PM3/2/10
to pytho...@python.org
On Tue, 2010-03-02 at 17:32 +0000, MRAB wrote:
> The documentation also mentions the 'pty' module. Have you tried that
> instead?

I tried to use pty.fork() but it also produces the same error.

I also tried passing 'r', and 'rb' to fdopen() but it didn't make any
difference.

-a


Albert Hopkins

unread,
Mar 2, 2010, 6:59:00 PM3/2/10
to pytho...@python.org
This appears to be Issue 5380[1] which is still open. I've cc'ed myself
to that issue.

[1] http://bugs.python.org/issue5380

0 new messages