[erlang-questions] C++ port having trouble printing to cout

3 views
Skip to first unread message

Erickson, John

unread,
Aug 17, 2009, 4:35:48 PM8/17/09
to erlang-q...@erlang.org
Hi, I have written a C++ port for some Erlang code and although I am able to get data in and out of the port without any problems, trying to do output in the C++ code with cout is unreliable. Usually if something is printed in Erlang after the call to the port returns, it will be printed instead of the last couple hundred lines of output from C++. I have tried putting cout.flush() in my code but it does not help. Single stepping through the code in gdb will print all output, but anytime I run at full speed I lose output.

John

Michael Truog

unread,
Aug 17, 2009, 5:08:56 PM8/17/09
to Erickson, John, erlang-q...@erlang.org
Erlang ports normally use stdin/stdout for communication. To change it
use erlang:open_port/2 with option nouse_stdio so that erlang does not
communicate on stdin/stdout. Remember std::cerr is still available
either way, and for some reason the linux/unix erlang shell prefers
"\r\n" instead of std::endl ("\n") when outputting to stderr.

Erickson, John wrote:
> Hi, I have written a C++ port for some Erlang code and although I am able to get data in and out of the port without any problems, trying to do output in the C++ code with cout is unreliable. Usually if something is printed in Erlang after the call to the port returns, it will be printed instead of the last couple hundred lines of output from C++. I have tried putting cout.flush() in my code but it does not help. Single stepping through the code in gdb will print all output, but anytime I run at full speed I lose output.
>
> John
>
>


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Erickson, John

unread,
Aug 17, 2009, 5:31:12 PM8/17/09
to Michael Truog, erlang-q...@erlang.org
Thanks for the suggestion, but that doesn't seem to solve my problem. I should have mentioned earlier, I am using spawn_driver, which I believe does not use any file descriptors. I also tried using cerr, but it does not seem to work any better.
Reply all
Reply to author
Forward
0 new messages