I think you can define Module['stdout'], see this test:

https://github.com/emscripten-core/emscripten/blob/7e538a419c3649f3a540a57beab347aa8f6c6271/tests/test_core.py#L4895-L4926

That function should receive the character code of each byte written. So
you could construct the binary data from that.

(But it would be more efficient to write to a file, and get the entire file
at once as an array, usually.)

- Alon


On Thu, Aug 12, 2021 at 10:24 AM [email protected] <
[email protected]> wrote:

> Hello, I'm compiling a C++ tool that outputs binary to stdout and I'm
> running into a similar issue but in the browser. I'm curious whether
> there's now a way to support this without modifying the code by any chance?
> Thank you!
>
>
> On Friday, November 8, 2013 at 3:28:09 PM UTC-8 Alon Zakai wrote:
>
>> Simplest option is to write to a file, not to stdout or stderr. For
>> stdout and stderr, we might be missing some binary stream support in node,
>> you might be the first person to try that...
>>
>> - Alon
>>
>>
>>
>> On Thu, Nov 7, 2013 at 12:42 PM, Daniel Baulig <[email protected]> wrote:
>>
>>> Sorry for reviving an old thread but I'm running into a very similar
>>> issue right now (found this while searching for a possible solution).
>>>
>>> I'm having a small C program that outputs binary data to stdout using
>>> fwrite. I usually invoke it like prog >outfile. It will also output some
>>> debugging data to stderr. This works flawless when compiled using gcc, but
>>> failed when compiled with emcc and run with node. The output to stderr will
>>> occasinally be corrupted. This only happens with the next output to stderr
>>> after a fwrite call. Also, the data output to stdout is corrupted and is
>>> not the same as the data written by the gcc compiled version. I randomly
>>> checked the data in the buffer before it is written to stdout by writing
>>> some bytes to stderr using fprintf(stderr, "%x%x\t") and all the bytes i've
>>> checked in the buffer are the same for the gcc and the emcc version of the
>>> binary. So the corruption must happen after calling fwrite inside the emcc
>>> stdio implementation. I tried putting the stdout stream into binary mode
>>> with freopen(NULL, "wb", stdout); before writing binary data to it, but
>>> that didn't help either.
>>> Anyone any suggestions?
>>>
>>> - Daniel
>>>
>> --
>>>
>> 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 [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/aaa95dab-0be9-439e-9b14-7b426f94d24dn%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/aaa95dab-0be9-439e-9b14-7b426f94d24dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpS7xZp_XMCaJaL1u7o__DDSrMMb6BjcfzGhR%2B%2BYirgLiA%40mail.gmail.com.

Reply via email to