www.digitalmars.com         C & C++   DMDScript  

D.gnu - Flush to stdio?

reply "Dleaner" <bm.email01 gmail.com> writes:
I was using writef("escape string" ~ "Display string") to try to 
simulate a console, but noticed that the writes are only flushed 
when a newline is present.

Is there a 'flush' function that works with stdio?
'flush()' seems unkown to the compiler, and 'fflush()' seems to 
be for files, not for writing to the screen.
Apr 01 2013
next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--0021cc022066d4e51304d950e67b
Content-Type: text/plain; charset=ISO-8859-1

On 1 April 2013 19:13, Dleaner <bm.email01 gmail.com> wrote:

 I was using writef("escape string" ~ "Display string") to try to simulate
 a console, but noticed that the writes are only flushed when a newline is
 present.

 Is there a 'flush' function that works with stdio?
 'flush()' seems unkown to the compiler, and 'fflush()' seems to be for
 files, not for writing to the screen.

You mean stdout.flush() ? -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --0021cc022066d4e51304d950e67b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= April 2013 19:13, Dleaner <span dir=3D"ltr">&lt;<a href=3D"mailto:bm.email= 01 gmail.com" target=3D"_blank">bm.email01 gmail.com</a>&gt;</span> wrote:<= br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left= :1px #ccc solid;padding-left:1ex"> I was using writef(&quot;escape string&quot; ~ &quot;Display string&quot;) = to try to simulate a console, but noticed that the writes are only flushed = when a newline is present.<br> <br> Is there a &#39;flush&#39; function that works with stdio?<br> &#39;flush()&#39; seems unkown to the compiler, and &#39;fflush()&#39; seem= s to be for files, not for writing to the screen.<br> </blockquote></div><br><br></div><div class=3D"gmail_extra">You mean stdout= .flush() ?<br clear=3D"all"></div><div class=3D"gmail_extra"><br>-- <br>Iai= n Buclaw<br><br>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;; </div></div> --0021cc022066d4e51304d950e67b--
Apr 01 2013
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/1/13, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 You mean stdout.flush() ?

Don't forget seat.putDown() too!
Apr 01 2013
prev sibling next sibling parent "DLearner" <bm.email01 gmail.com> writes:
On Monday, 1 April 2013 at 18:36:52 UTC, Iain Buclaw wrote:
 On 1 April 2013 19:13, Dleaner <bm.email01 gmail.com> wrote:

 I was using writef("escape string" ~ "Display string") to try 
 to simulate
 a console, but noticed that the writes are only flushed when a 
 newline is
 present.

 Is there a 'flush' function that works with stdio?
 'flush()' seems unkown to the compiler, and 'fflush()' seems 
 to be for
 files, not for writing to the screen.

You mean stdout.flush() ?

Tried your idea, error message was: "No property 'flush' for type '_iobuf'
Apr 01 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--20cf302ef79eb2b26f04d9514ca3
Content-Type: text/plain; charset=ISO-8859-1

On 1 April 2013 19:45, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:

 On 4/1/13, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 You mean stdout.flush() ?

Don't forget seat.putDown() too!

Oh, and also forgot about hands.wash(). -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --20cf302ef79eb2b26f04d9514ca3 Content-Type: text/html; charset=ISO-8859-1 <div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 1 April 2013 19:45, Andrej Mitrovic <span dir="ltr">&lt;<a href="mailto:andrej.mitrovich gmail.com" target="_blank">andrej.mitrovich gmail.com</a>&gt;</span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 4/1/13, Iain Buclaw &lt;<a href="mailto:ibuclaw ubuntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt; You mean stdout.flush() ?<br> <br> Don&#39;t forget seat.putDown() too!<br> </blockquote></div><br></div><div class="gmail_extra">Oh, and also forgot about hands.wash().<br><br><br clear="all"></div><div class="gmail_extra"><br>-- <br>Iain Buclaw<br><br>*(p &lt; e ? p++ : p) = (c &amp; 0x0f) + &#39;0&#39;; </div></div> --20cf302ef79eb2b26f04d9514ca3--
Apr 01 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--0022158c0dc1e0184c04d9515582
Content-Type: text/plain; charset=ISO-8859-1

On 1 April 2013 19:49, DLearner <bm.email01 gmail.com> wrote:

 On Monday, 1 April 2013 at 18:36:52 UTC, Iain Buclaw wrote:

 On 1 April 2013 19:13, Dleaner <bm.email01 gmail.com> wrote:

  I was using writef("escape string" ~ "Display string") to try to simulate
 a console, but noticed that the writes are only flushed when a newline is
 present.

 Is there a 'flush' function that works with stdio?
 'flush()' seems unkown to the compiler, and 'fflush()' seems to be for
 files, not for writing to the screen.

You mean stdout.flush() ?

Tried your idea, error message was: "No property 'flush' for type '_iobuf'

stdout should be a struct File if you imported std.stdio; As if looks like the C stdout is taking precedence, you can either force the use of it via std.stdio.stdout.flush() , or call fflush(stdout). Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --0022158c0dc1e0184c04d9515582 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= April 2013 19:49, DLearner <span dir=3D"ltr">&lt;<a href=3D"mailto:bm.emai= l01 gmail.com" target=3D"_blank">bm.email01 gmail.com</a>&gt;</span> wrote:= <br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef= t:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On Monday, 1 April 2013 at 18:36:52 UTC, Iain Buclaw wrot= e:<br> </div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l= eft:1px #ccc solid;padding-left:1ex"><div class=3D"im"> On 1 April 2013 19:13, Dleaner &lt;<a href=3D"mailto:bm.email01 gmail.com" = target=3D"_blank">bm.email01 gmail.com</a>&gt; wrote:<br> <br> </div><div><div class=3D"h5"><blockquote class=3D"gmail_quote" style=3D"mar= gin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I was using writef(&quot;escape string&quot; ~ &quot;Display string&quot;) = to try to simulate<br> a console, but noticed that the writes are only flushed when a newline is<b= r> present.<br> <br> Is there a &#39;flush&#39; function that works with stdio?<br> &#39;flush()&#39; seems unkown to the compiler, and &#39;fflush()&#39; seem= s to be for<br> files, not for writing to the screen.<br> <br> </blockquote> <br> <br></div></div> You mean stdout.flush() ?<br> </blockquote> <br> Tried your idea, error message was:<br> &quot;No property &#39;flush&#39; for type &#39;_iobuf&#39;<br> </blockquote></div><br></div><div class=3D"gmail_extra">stdout should be a = struct File if you imported std.stdio;<br><br><br>As if looks like the C st= dout is taking precedence, you can either force the use of it via std.stdio= .stdout.flush() , or call fflush(stdout).<br clear=3D"all"> </div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">Regar= ds<br></div><div class=3D"gmail_extra">-- <br>Iain Buclaw<br><br>*(p &lt; e= ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;; </div></div> --0022158c0dc1e0184c04d9515582--
Apr 01 2013
prev sibling next sibling parent "Kagamin" <spam here.lot> writes:
You can also try to call setvbuf on stdio with _IONBF mode to set 
it to non-buffering mode.
Apr 01 2013
prev sibling next sibling parent "Kagamin" <spam here.lot> writes:
oops, stdout.
int zero=setvbuf(stdout,null,_IONBF,0);
assert(zero==0);

or

stdio.setvbuf(0,_IONBF);
Apr 01 2013
prev sibling parent "DLearner" <bmqazwsx123 gmail.com> writes:
On Monday, 1 April 2013 at 19:07:55 UTC, Iain Buclaw wrote:
 On 1 April 2013 19:49, DLearner <bm.email01 gmail.com> wrote:

 On Monday, 1 April 2013 at 18:36:52 UTC, Iain Buclaw wrote:

 On 1 April 2013 19:13, Dleaner <bm.email01 gmail.com> wrote:

  I was using writef("escape string" ~ "Display string") to 
 try to simulate
 a console, but noticed that the writes are only flushed when 
 a newline is
 present.

 Is there a 'flush' function that works with stdio?
 'flush()' seems unkown to the compiler, and 'fflush()' seems 
 to be for
 files, not for writing to the screen.

You mean stdout.flush() ?

Tried your idea, error message was: "No property 'flush' for type '_iobuf'

stdout should be a struct File if you imported std.stdio; As if looks like the C stdout is taking precedence, you can either force the use of it via std.stdio.stdout.flush() , or call fflush(stdout). Regards

Your suggestion of: fflush(stdout); worked. Thank you.
Apr 02 2013