开发者

mnesia save out info

开发者 https://www.devze.com 2023-02-21 18:26 出处:网络
how to save mnesia:info() out开发者_如何学Goput? I use remote sh in unix screen and can\'t to scroll windowHere\'s a function that you can put in the user_default.erl module on the remote node:

how to save mnesia:info() out开发者_如何学Goput?

I use remote sh in unix screen and can't to scroll window


Here's a function that you can put in the user_default.erl module on the remote node:

  out(Fun, File) ->
    G = erlang:group_leader(),
    {ok, FD} = file:open(File, [write]),
    erlang:group_leader(FD, self()),
    Fun(),
    erlang:group_leader(G, self()),
    file:close(FD).

Then, you can do the following (after recompiling and loading user_default):

  1> out(fun () -> mnesia:info() end, "mnesia_info.txt").

Or, just cut-and paste the following into the shell:

  F = fun (Fun, File) ->
        G = erlang:group_leader(),
        {ok, FD} = file:open(File, [write]),
        erlang:group_leader(FD, self()),
        Fun(),
        erlang:group_leader(G, self()),
        file:close(FD)
      end,
  F(fun () -> mnesia:info() end, "mnesia_info.txt").


In cases where you are situated at a terminal without scrolling (if you are on a xterm and see no scrollbar simply switch it on) a tool very useful is screen: it provides virtual vt100 termials, you can switch between terminals even detach from it and come back later (nice for long running programs on remote serversthat need the occasional interaction).

And you can log transcripts to a file and scroll in the output of the virtual terminal.

If you are on a Unix like System you will probably be able to just install a pre-built package, if all else fails you can always pick up the source and build it yourself.

Also look at this article for other solutions.

If you are not able to install screen on the system, a simple but not very comfortable hack that only uses Unix built-in stuff is:

Start erlang shell with tee(1) to redirect the output:

$ erl | tee output.log
Eshell V5.7.5  (abort with ^G)
1> mnesia:info().
===> System info in version {mnesia_not_loaded,nonode@nohost,
                                {1301,742014,571300}}, debug level = none <===
opt_disc. Directory "/usr/home/peer/Mnesia.nonode@nohost" is NOT used.
use fallback at restart = false
running db nodes   = []
stopped db nodes   = [nonode@nohost] 
ok
2>    

Its a bit hard to get out of the shell (you probably have to type ^D to end the input file) but then you have the tty output in the file:

$ cat output.log 
Eshell V5.7.5  (abort with ^G)
1> ===> System info in version {mnesia_not_loaded,nonode@nohost,
                                {1301,742335,572797}}, debug level = none <===
...


I believe you cant. See system_info(all).


Convert to a string:

S = io_lib:format("~p~n", [mnesia:info()]).

Then write it to disk.

0

精彩评论

暂无评论...
验证码 换一张
取 消