将erlang shell的输出重定向到一个文件中 [英] Redirect output from erlang shell into a file

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

问题描述

有没有办法通过 io:format()将数据从erlang shell重定向到一个文件?我知道我可以打开一个文件(IoDevice)并将数据直接写入它,但它需要代码更改,我现在不想做。

Is there a way to redirect data printed by io:format() from erlang shell into a file ? I know that I can open a file (IoDevice) and write data directly into it, but it requires code change and I don't want to do now.

推荐答案

只需运行 erl -noinput -s module function -s init stop>文件

这是一个例子。

Erlang代码:

-module(test).    
-compile(export_all).

function() ->
   io:fwrite("Hello world!~n").

在shell中:

$ erlc test.erl 
$ erl -noinput -s test function -s init stop > test.txt
$ cat test.txt
Hello world!

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

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