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


Groups > comp.unix.programmer > #1201

Re: How to automatically flush stdout when a read from stdin occurs.

From Rainer Weikusat <rweikusat@mssgmbh.com>
Newsgroups comp.unix.programmer
Subject Re: How to automatically flush stdout when a read from stdin occurs.
Date 2011-09-02 13:50 +0100
Message-ID <87obz3rtut.fsf@sapphire.mobileactivedefense.com> (permalink)
References <500542b0-0d1d-4f96-9c17-2d77aacfd1b9@k29g2000yqf.googlegroups.com>

Show all headers | View raw


tm <thomas.mertes@gmx.at> writes:
> The standard behaviour of stdin and stdout is (when a program is
> started from a shell window):
>
>   Whenever I read from stdin a fflush(stdout) is automatically done,
>   before data is read from stdin. This allows nice interactive
>   behaviour.
>
> But when I connect to the same program via two pipes no such
> flushing occurs.
>
> My man page about stdio contains the following paragraph:
>
>   Output streams that refer to terminal devices are always line
>   buffered by default; pending output to such streams is written
>   automatically whenever an input stream that refers to a terminal
>   device is read.

[...]

> The child process could find out that stdin and stdout are connected
> with pipes (fstat() and check st_mode for S_IFIFO) and set stdout
> to line buffering (with setvbuf()), but how can I get the
>
>   read from stdin causes flush of stdout
>
> behaviour?
> Can the child process do something like:
>
>   interactive_io(stdin, stdout);
>
> To get the automatic flush behaviour?

This isn't exactly the answer to your question but usually, when you
want to remote-control an interactive program (for instance, in the
way ssh enables using a shell interactively despite using TCP for
I/O), you should be using a pseudo-terminal pair (pty) instead of a
pipe because that is 'an interactive device'.

Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to automatically flush stdout when a read from stdin occurs. tm <thomas.mertes@gmx.at> - 2011-09-02 02:20 -0700
  Re: How to automatically flush stdout when a read from stdin occurs. Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-09-02 13:50 +0100
    Re: How to automatically flush stdout when a read from stdin occurs. tm <thomas.mertes@gmx.at> - 2011-09-03 02:10 -0700
      Re: How to automatically flush stdout when a read from stdin occurs. Nobody <nobody@nowhere.com> - 2011-09-03 13:05 +0100
  Re: How to automatically flush stdout when a read from stdin occurs. Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-02 20:43 -0400
  Re: How to automatically flush stdout when a read from stdin occurs. gordonb.j3p91@burditt.org (Gordon Burditt) - 2011-09-02 23:56 -0500
    Re: How to automatically flush stdout when a read from stdin occurs. Nobody <nobody@nowhere.com> - 2011-09-03 09:08 +0100

csiph-web