Io 在没有提示的情况下从StdIn读取Erlang

Io 在没有提示的情况下从StdIn读取Erlang,io,erlang,stdout,stdin,Io,Erlang,Stdout,Stdin,我刚读了Erlang的IO模块,所有的输入函数都以提示符()开头 我有一个程序a,它将输出通过管道传输到我的Erlang程序B,因此将a的stdout转换为B的stdin 我怎么能在一个循环中读到这个标准, 因为我每个圣诞节都会收到味精 我想要的是这样的东西 loop()-> NewMsg = readStdIn() %% thats the function I am looking for do_something(NewMsg), loop. 我刚读了Erlang的IO

我刚读了Erlang的IO模块,所有的输入函数都以提示符()开头

我有一个程序a,它将输出通过管道传输到我的Erlang程序B,因此将a的
stdout
转换为B的
stdin

我怎么能在一个循环中读到这个标准, 因为我每个圣诞节都会收到味精

我想要的是这样的东西

loop()->
  NewMsg = readStdIn() %% thats the function I am looking for
  do_something(NewMsg),
  loop.
我刚读了Erlang的IO模块,所有的输入函数都以提示符()开头

看起来您可以使用
进行提示。从标准输入读取面向行的输入:

-module(my).
-compile(export_all).

read_stdin() ->
    case io:get_line("") of
        eof ->
            init:stop(); 
        Line ->
            io:format("Read from stdin: ~s", [Line]),
            read_stdin()
    end.
在bash shell中:

~/erlang_programs$ erl -compile my.erl
my.erl:2: Warning: export_all flag enabled - all functions will be exported

~/erlang_programs$ echo -e "hello\nworld" | erl -noshell -s my read_stdin
Read from stdin: hello
Read from stdin: world
~/erlang_programs$ 

看到了吗?

是的,而且空字符串似乎适用于提示,我只是认为必须有另一种方法