-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fflush does not flush stdout or stderr in browser environment. #2770
Comments
Looking at the source, the cause is simply that |
Implemented this in the above pull request. One limitation of our fflush is that it will always cause a newline to be printed. |
Ran into the same issue, very confusing until I realized fflush wasn't working. |
Ouch, the situation is a bit trickier than I thought. I had to revert the The main problem is that since printing to a web console is line-based, we cannot The old behavior where I'm not sure what's a good way to proceed here. One might be to attempt to remove the use of If anyone has better suggestions, let me know. |
I thought we already flush when we exit main? (I think when we shut down the FS) When I tested that now it worked using Flushing on each main loop iteration is interesting. I'm sure it would help some things, but also break others. Not sure what is best. |
We flush when we exit main only when user did not call |
I see, ok. Yes, we can't fix this 100%. I don't have any other ideas. |
We could do a "#define printf emscripten_internal_printf" in "emscripten.h" before the "stdio.h". I think it could also work for the STL (cout ...). In "emscripten_internal_printf()" we will know the state of the buffer. It is may be "fread/fwrite" to trap... It is based on my understanding that the standart functions are replaced at link time. May be I'm wrong... dlmalloc do that for malloc(). |
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
It looks to me like the solution to this would be to move the endline handling to the javascript side. So that '\n' is sent normal to javascript. Also note I've put some effort into implementing xterm at https://github.com/xloem/emterm which provides better for flushes of partial lines. |
@kripken Also hit the same issue while using busybox for an in-browser terminal application (https://busytex.github.io). In particular, busybox clear doesn't print a new line: https://github.com/brgl/busybox/blob/master/console-tools/clear.c This is aggravated by the fact that I don't let the emscripten module clean up and exit, and instead I reset the module's memory myself. @sbc100 Is there a way to manually flush the streams from JavaScript side? |
Place the following code in the file
test.cpp
:and compile with
emcc test.cpp -o test.html -s NO_EXIT_RUNTIME=1
. Then run the resultingtest.html
in the browser.Observed: No text is printed.
Expected: fflush should flush, and both texts should be visible.
The text was updated successfully, but these errors were encountered: