另一种实用的接入erlang控制台的方法

转载:http://www.iteye.com/topic/362394

能对运行中的erl系统进行控制是非常重要的一个福利,但是假如你的erl系统是后台运行的, 根本就没有shell可以让你输入。


如果你的节点有name 那么可以用JCL 或者-remsh 接入. 否则的话 你就得用如下方法:

请先参考 Embedded Systems User's Guide. 这种方式的好处是你的所有输入输出都记录在log文件里面 方便你日后查阅。


先运行
[root@localhost R13A]# which erl
/usr/local/bin/erl
确认下你的erl系统安装在那个路径。

[root@localhost bin]# /usr/local/lib/erlang/bin/start
但是我用的R12B5或者R13A发行版这样有点小问题 start没有运行起来, 我调查了半天发现有2个问题:

1. run_erl的log是设定在/usr/local/lib/erlang/log但是没有这个目录, 通过运行mkdir /usr/local/lib/erlang/log搞定

2. /usr/local/lib/erlang/releases/R13A/sys.config文件没有.
其中 R13A可能是R12B5.
通过运行echo "[]." >  /usr/local/lib/erlang/releases/R13A/sys.config搞定

做了以上的步骤,现在运行
[root@localhost ~]# ps -ef|grep beam
root     19947 19946  0 03:35 pts/3    00:00:00 /usr/local/lib/erlang/erts-5.7/bin/beam.smp -- -root /usr/local/lib/erlang -progname start_erl -- -home /root -boot /usr/local/lib/erlang/releases/R13A/start -config /usr/local/lib/erlang/releases/R13A/sys
确认beam已经运行, 同时/tmp/目录下有erlang.pipe.1.r  erlang.pipe.1.w 的pipe.

如果还没有运行起来 那么就看下 tail /var/log/syslog 查明出错原因

收获的时候到了
[root@localhost bin]# to_erl
Attaching to /tmp/erlang.pipe.3 (^D to exit)
1> 
1> 
1> 

看到熟悉的shell提示符号了。退出的时候记得用^D, 而不是^C. 

/* 
* Module: run_erl.c

* This module implements a reader/writer process that opens two specified 
* FIFOs, one for reading and one for writing; reads from the read FIFO
* and writes to stdout and the write FIFO.
*
  ________                            _________ 
|        |--<-- pipe.r (fifo1) --<--|         |
| to_erl |                          | run_erl | (parent)
|________|-->-- pipe.w (fifo2) -->--|_________|
                                          ^ master pty
                                          |
                                          | slave pty
                                      ____V____ 
                                     |         |
                                     |  "erl"  | (child)
                                     |_________|

run_erl和to_erl是通用的pipe封装器 我们也可以这样用:

/usr/local/lib/erlang/bin/run_erl  -daemon /tmp/ /tmp/log "exec lua" 

to_erl
这时候我们看到的是 lua的shell

posted on 2013-06-04 10:36  Bo.Zhang  阅读(198)  评论(0)    收藏  举报