用户如何知道用户将erlang shell的输出重定向到文件中 [英] How to know when user redirect output from erlang shell into a file

查看:152
本文介绍了用户如何知道用户将erlang shell的输出重定向到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个样本模块


    -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).

我的问题是:


  1. 如何知道用户将erlang shell的输出重定向到一个文件?

  2. 如何写入text.txt内容只是Hello world!不是^ [[31mHello world!^ [[0m

谢谢。

推荐答案

看看 http://www.erlang.org/doc/man/init.html#get_arguments-0 ,您可以检查noshell标志是否存在相应的采用输出。

Have a look to http://www.erlang.org/doc/man/init.html#get_arguments-0, you can check for the existence of "noshell" flag there an adopt output accordingly.

[{root,[/ opt / local / lib / erlang]},{progname,[erl]},{home,[/ Users /...\">},{noshell,[]}]]},{helloworld,main,0},{init,start_it,1},{init,start_em,1}]

这篇关于用户如何知道用户将erlang shell的输出重定向到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆