我有一个示例模块
-module(helloworld).
-compile(export_all).
main() -> io:format("~s~s~s~n",["\e[31m","Hello world!","\e[0m"]).
当我构建时:
erlc helloworld.erl
之后,我运行:
erl -noshell -s helloworld main -s init stop
Hello world! (with red color)
erl -noshell -s helloworld main -s init stop > text.txt
^[[31mHello world!^[[0m (The content in text.txt is ugly, so I don't like).
我的问题是:
- 如何知道用户何时将输出从 erlang shell 重定向到文件?
- 我怎样才能将内容写入text.txt“Hello world!”不是“^[[31m你好世界!^[[0m”
Thanks.
看看http://www.erlang.org/doc/man/init.html#get_arguments-0 http://www.erlang.org/doc/man/init.html#get_arguments-0,您可以检查是否存在“noshell”标志,并相应地采用输出。
[{root,["/opt/local/lib/erlang"]},{progname,["erl"]},{home,["/Users/..."]},{noshell,[]}]]},{helloworld,main,0},{init,start_it,1},{init,start_em,1}]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)