You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you help me understand why emscripten behaves differently on stderr message ending with \n vs. \r.
Here is a necessary code change in ffmpeg code changing \r for \n so emscripten properly calls printErr() callback for every single message. Using the original \r it would only call printErr() once at the very end with all the messages concatenated together.
Or is there a compile time flag in emscripten that can be used so no code change is needed?
The printErr callback mechanism doesn't currently have any way to represent a carriage return, or any kind of partial line of output. The only thing it supports is a complete line of output (that ends in a newline). IIUC this is due to the fact the its default implementation is based on console.error which is fundamentally line-based.. so it has to wait for a compete line.
\r essentially erases the current line before it is complete and overwrites it with new content. It assumes that some kind of tty or console is attached, and this is not compatible with JavaScripts console.log/warning/error API. We would need to extent the printErr mechanism within emscripten to support something like that. Its not inconceivable but its also not obvious (to me) how to make this work.
Thanks for the insights @sbc100 . Is this something that can be considered a feature request? I guess there is plenty of libs that can benefit from reading carriage return line "updates"
I ended up using stderr/stdout instead of print and printErr, this way my code gets notified asap with any incomming data, however byte-by-byte by default.
Furher I modified compiled myModule.js and replaced its plain content:
Activity
sbc100 commentedon Jan 27, 2022
The
printErrcallback mechanism doesn't currently have any way to represent a carriage return, or any kind of partial line of output. The only thing it supports is a complete line of output (that ends in a newline). IIUC this is due to the fact the its default implementation is based onconsole.errorwhich is fundamentally line-based.. so it has to wait for a compete line.\ressentially erases the current line before it is complete and overwrites it with new content. It assumes that some kind of tty or console is attached, and this is not compatible with JavaScriptsconsole.log/warning/errorAPI. We would need to extent theprintErrmechanism within emscripten to support something like that. Its not inconceivable but its also not obvious (to me) how to make this work.[-]newline character on stderr[/-][+]Carriage Return "\r" character on stderr[/+]jozefchutka commentedon Jan 27, 2022
Thanks for the insights @sbc100 . Is this something that can be considered a feature request? I guess there is plenty of libs that can benefit from reading carriage return line "updates"
sbc100 commentedon Jan 27, 2022
Yup, I think it would be nice to have a better story for TTY/console output.
jozefchutka commentedon Apr 15, 2022
I ended up using
stderr/stdoutinstead ofprintandprintErr, this way my code gets notified asap with any incomming data, however byte-by-byte by default.Furher I modified compiled myModule.js and replaced its plain content:
by:
Now I can read a whole chunk of bytes at once, with some more logic for buffering,
\nand\rdetection etc.:Its a bit ugly but fast. I am wondering if there are options:
Or should I start another thread for seek help / requesting such design?
jozefchutka commentedon Apr 19, 2022
Closing this issue in favor of #16755