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


Groups > comp.lang.python > #88620 > unrolled thread

Re: Help with pipes, buffering and pseudoterminals

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2015-04-07 16:28 -0600
Last post2015-04-07 16:28 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help with pipes, buffering and pseudoterminals Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-07 16:28 -0600

#88620 — Re: Help with pipes, buffering and pseudoterminals

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-04-07 16:28 -0600
SubjectRe: Help with pipes, buffering and pseudoterminals
Message-ID<mailman.119.1428445767.12925.python-list@python.org>
On Tue, Apr 7, 2015 at 4:06 PM, Cameron Simpson <cs@zip.com.au> wrote:
> On 07Apr2015 20:38, Chris Angelico <rosuav@gmail.com> wrote:
>>
>> On Tue, Apr 7, 2015 at 3:48 PM, Cameron Simpson <cs@zip.com.au> wrote:
>>>
>>> The operating system arranges the commection of the shell to the
>>> terminal.
>>> Your usual program has by default a stdin, stdout and stderr. These are
>>> _all_ the same file handle, duplicated to each of the three file
>>> descriptors
>>> 0, 1 and 2 respectively. On the operating system side, the OS has
>>> performed
>>> _one_ open() call on the terminal device and handed the caller a single
>>> file
>>> descriptor. The caller then calls dup() (or modernly, dup2()) to present
>>> the
>>> open terminal as stdin, stdout and stderr.
>>
>>
>> Really? I can believe that stdout and stderr are initially duplicates,
>> but stdin as well? Isn't stdin opened for reading only, and
>> stdout/stderr for writing only?
>
>
> No. Have a look with lsof:
>
>  lsof -p $$
>
> in a terminal.

sys.stdin and sys.stdout are distinct, uni-directional io objects. At
a lower level though, the only thing stopping you from calling
os.write on fd 0 or os.read on fd 1 or 2 is convention.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web