stdout in browsers can only be flushed on a newline, because console.log()
and console.error() can only print out full lines and never individual
characters. That is how it should currently work.

(for printing to a text box in a browser page, it would be possible to
flush in arbitrary points in time, though this is not implemented)

I'm not sure about node.js stdout print functions, but I presume it also
flushes only on a newline? Or is possible to print out without a newline?

The pull request implemented support for flushing on explicit points in
time, but the issue was that it could not avoid that each flush introduces
a newline, so it ended up printing newlines in the middle of lines.

Though if reverting that commit does not affect the issue, then the problem
might be somewhere else, not sure about that then.


2016-09-22 3:38 GMT+03:00 Grant Rostig <grantrost...@gmail.com>:

> Hi JJ,
>
> Thank you for your suggestions, but they seem impractical, nor would they
> fix the at least two problems as far as I can tell.
>
> So the currently prevailing idea seems to be that fflush had to be
> disabled/removed to fix (not really fix) a problem with cerr?
>
> I hope someone who is familiar with the code can fix both fflush and
> cerr.  This is very important to be able to run legacy code.
>
> ++Regards,
>
> Grant
>
>
> On Tuesday, September 20, 2016 at 10:32:35 PM UTC-5, Grant Rostig wrote:
>>
>> Hi,
>>
>>
>> printf and cout are not flushed before input is prompted at the command
>> line.
>>
>>
>> This problem exists in chrome and firefox running on linux fedora 24.
>> Also even running the a.out.js program in node, has the same problems.
>>
>>
>> This example code works fine in native linux however with emscrpten
>> nothing works as expected.  However using \n does improve the situation by
>> showing the input prompt before waiting for keyboard input.
>>
>>
>> All systems and software are fully updated.This problem has been
>> reported  on this list since 2013.  I read all the suggestions on multiple
>> posts and nothing has worked, short of re-writing in asynchronous
>> javascript (which I have not attempted).
>>
>>
>> Here is the code I wrote to demonstrate that none of the suggestions that
>> I found work:
>>
>>
>> Thanks in advance for any help.
>>
>> ++Regards, Grant
>>
>>
>> #include <iostream>
>> #include <string>
>> #include <stdio.h>
>>
>> void get_input_cout_nl(std::string& ttyinput_ref) {
>>     std::cout << "Print hello world output via cout_nl? (y/n):\n";
>>     std::cin >> ttyinput_ref;
>> }
>>
>> void get_input_cout_endl(std::string& ttyinput_ref) {
>>     std::cout << "Print hello world output via cout_endl? (y/n):" <<
>> std::endl;
>>     std::cin >> ttyinput_ref;
>> }
>>
>> void get_input_cout_flush(std::string& ttyinput_ref) {
>>     std::cout << "Print hello world output via cout_flush? (y/n):" <<
>> std::flush;
>>     flush(std::cout);  // doesn't help
>>     std::cin >> ttyinput_ref;
>> }
>>
>> void get_input_cout(std::string& ttyinput_ref) {
>>     std::cout << "Print hello world output cout? (y/n):";
>>     std::cin >> ttyinput_ref;
>> }
>>
>> void get_input_printf_nl(std::string& ttyinput_ref) {
>>     printf("Print hello world output printf_nl? (y/n):\n");
>>     char temp[80];
>>     scanf("%s", temp);
>>     ttyinput_ref = temp;
>> }
>>
>> void get_input_printf_flush(std::string& ttyinput_ref) {
>>     printf("Print hello world output printf? (y/n):");
>>     fflush(stdout);
>>     char temp[80];
>>     scanf("%s", temp);
>>     ttyinput_ref = temp;
>> }
>>
>> void get_input_printf(std::string& ttyinput_ref) {
>>     printf("Print hello world output printf_nl? (y/n):");
>>     char temp[80];
>>     scanf("%s", temp);
>>     ttyinput_ref = temp;
>> }
>>
>> int main()
>> {
>>     std::cin.tie(&std::cout); // does not change anything as far as I can
>> tell.
>>     std::string ttyinput = {"default"};
>>     std::string yy = {"y"};
>>     for (int j = 6; j>=0; --j ) {   // one can run these tests in either
>> order and get same result (I had thought that cout might mess up the stream
>> for printf, so tested each first)
>>         switch (j) {
>>             case 0: get_input_cout_nl(      ttyinput); break;
>>             case 1: get_input_cout_endl(    ttyinput); break;
>>             case 2: get_input_cout_flush(   ttyinput); break;
>>             case 3: get_input_cout(         ttyinput); break;
>>
>>             case 4: get_input_printf_nl(    ttyinput); break;
>>             case 5: get_input_printf_flush( ttyinput); break;
>>             case 6: get_input_printf(       ttyinput); break;
>>         }
>>         if (ttyinput == "y") {
>>             std::cout << "Hello World!" << std::endl;
>>         } else {
>>             std::cout << "output not run." << std::endl;
>>         }
>>     }
>>     return 0;
>> }
>>
>>
>> Output from node.js:
>> [grostig@localhost emsripten1]$ emcc -v
>> emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld)
>> 1.36.0
>> clang version 3.9.0 (https://github.com/kripken/em
>> scripten-fastcomp-clang/ 271ce598c3d1fe74efadc254f5be1b57edea9f41) (
>> https://github.com/kripken/emscripten-fastcomp/
>> 61acfb230665464544f2e8db292f8999fc3c628c) (emscripten 1.36.0 : 1.36.0)
>> Target: x86_64-unknown-linux-gnu
>> Thread model: posix
>> InstalledDir: /home/grostig/src/emsdk_portab
>> le/clang/fastcomp/build_master_64/bin
>> Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/6.1.1
>> Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/6.1.1
>> Candidate multilib: .;@m64 <https://github.com/m64>
>> Candidate multilib: 32;@m32 <https://github.com/m32>
>> Selected multilib: .;@m64 <https://github.com/m64>
>> INFO:root:(Emscripten: Running sanity checks)
>> [grostig@localhost emsripten1]$
>>
>> [grostig@localhost emsripten1]$ emcc -std=gnu++11 main.cpp
>> [grostig@localhost emsripten1]$ node ./a.out.js
>> y
>> Print hello world output printf_nl? (y/n):Hello World!
>> y
>> Print hello world output printf? (y/n):Hello World!
>> Print hello world output printf_nl? (y/n):
>> y
>> Hello World!
>> y
>> Print hello world output cout? (y/n):Hello World!
>> y
>> Print hello world output via cout_flush? (y/n):Hello World!
>> Print hello world output via cout_endl? (y/n):
>> y
>> Hello World!
>> Print hello world output via cout_nl? (y/n):
>> y
>> Hello World!
>>
>>
>>
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to