Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100792

Re: What interface is a ‘Popen.stdout’ presenting?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From eryk sun <eryksun@gmail.com>
Newsgroups comp.lang.python
Subject Re: What interface is a ‘Popen.stdout’ presenting?
Date Wed, 23 Dec 2015 22:30:02 -0600
Lines 19
Message-ID <mailman.101.1450931445.2237.python-list@python.org> (permalink)
References <85d1twzlj2.fsf@benfinney.id.au> <858u4kzkyp.fsf@benfinney.id.au>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de 6m8+oqS06Bl/l7MPp9bkegUk9mDlUf99FjJ+p2pOplQw==
Return-Path <eryksun@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.022
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'descriptor': 0.09; 'python': 0.10; 'wed,': 0.15; "'r')": 0.16; '23,': 0.16; 'dup': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'file.': 0.22; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; 'open': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'skip:o 20': 0.38; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'close': 0.61; 'subjectcharset:utf-8': 0.71; '8bit%:27': 0.72
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=+8RngUpdhN1xGVbiHqscZQh7oI8/bYlOraAWtjrSEQs=; b=zsRNqNQPvrvspGNj8mkt6spAAlEJzleAqvs4YvTQca/kGVoaOTsQWQONmsWGt7+SFY 5uvL3FMu8IIvC+gfDa+Hmvaz7IDDFbnqu5jbYUIH6Ugy0hh4zHCdIDVc2pnWTO/cCEV+ NItyd0ya4MnfAgLx8iyNmTQSmXwRNKUhlao62TdBRAOLyeD4r7vQl0TFQtu1ZYcMULeL mFQqIIc32DMjvCHB5Rz5/NOVDxHaCkOdWVs8b2A0hSFmSBfc+kjUl+BJwYymX6ew0TPL ovqmZXEuI0uyfZFVGohL6OsoXk2QK1QJm8sOG7IfB6d+Rv8hgOk/Aoe5q4QnGCBi6o/V J2iw==
X-Received by 10.50.156.35 with SMTP id wb3mr27375514igb.55.1450931442399; Wed, 23 Dec 2015 20:30:42 -0800 (PST)
In-Reply-To <858u4kzkyp.fsf@benfinney.id.au>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100792

Show key headers only | View raw


On Wed, Dec 23, 2015 at 7:36 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> So how do I get from a Python 2 ‘file’ object, to whatever
> ‘io.TextIOWrapper’ wants?

I would dup the file descriptor and close the original file. Then open
the file descriptor using io.open:

    >>> p = subprocess.Popen(['uname'], stdout=subprocess.PIPE)
    >>> fd = os.dup(p.stdout.fileno())
    >>> fd
    4
    >>> p.stdout.close()
    >>> fout = io.open(fd, 'r')
    >>> fout
    <_io.TextIOWrapper name=4 encoding='UTF-8'>
    >>> fout.read()
    u'Linux\n'

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: What interface is a ‘Popen.stdout’ presenting? eryk sun <eryksun@gmail.com> - 2015-12-23 22:30 -0600

csiph-web