<div style="white-space:pre-wrap">Use erlexec in "async" mode instead:<br><a href="https://github.com/saleyn/erlexec">https://github.com/saleyn/erlexec</a><br><br></div><br><div class="gmail_quote"><div dir="ltr">Le mer. 16 nov. 2016 à 20:43, Stanislaw Klekot <<a href="mailto:erlang.org@jarowit.net">erlang.org@jarowit.net</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Nov 16, 2016 at 08:06:03PM +0100, Alex Feng wrote:<br class="gmail_msg">
> Hi,<br class="gmail_msg">
><br class="gmail_msg">
> I am using an port to communicate with an external program, I would like to<br class="gmail_msg">
> fetch each output from the external problem.<br class="gmail_msg">
> But I have problem to fetch the output when the external problem runs into<br class="gmail_msg">
> waiting input," scanf " for example.<br class="gmail_msg">
><br class="gmail_msg">
> Here is an example to communicate with a simple C program.<br class="gmail_msg">
><br class="gmail_msg">
> I need to fetch the prompt line("Please input you name") from Port in order<br class="gmail_msg">
> to interact with C code, but with "scanf" added in C code, I couldn't<br class="gmail_msg">
> fetch it from Port.<br class="gmail_msg">
> Does anyone know why is that ? Any advice and suggestions will be greatly<br class="gmail_msg">
> appreciated.<br class="gmail_msg">
[...]<br class="gmail_msg">
> C code:<br class="gmail_msg">
><br class="gmail_msg">
> int main()<br class="gmail_msg">
> {<br class="gmail_msg">
><br class="gmail_msg">
> char str[10];<br class="gmail_msg">
><br class="gmail_msg">
> printf("Please input you name:"); //Prompt line<br class="gmail_msg">
><br class="gmail_msg">
> scanf ("%9s",str); // with this line, port can not read the output from this program.<br class="gmail_msg">
><br class="gmail_msg">
> return 1;<br class="gmail_msg">
> }<br class="gmail_msg">
<br class="gmail_msg">
It's because STDOUT buffering differs between running things in terminal<br class="gmail_msg">
directly and running them with STDOUT redirected somewhere. You can see<br class="gmail_msg">
it yourself by first running this "a.out" in shell, and then running it<br class="gmail_msg">
redirected to cat: "a.out | cat". In the latter case you won't get<br class="gmail_msg">
prompt.<br class="gmail_msg">
<br class="gmail_msg">
You need to call fflush() to flush anything buffered by printf() (see<br class="gmail_msg">
its man page for details).<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Stanislaw Klekot<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
erlang-questions mailing list<br class="gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg">
</blockquote></div>