|
|
| Author |
Message |
|
| vladdu |
Posted: Fri Nov 03, 2006 12:45 pm |
|
|
|
User
Joined: 28 Feb 2005
Posts: 397
Location: Gothenburg, Sweden
|
Following my own question about this, and using my lunch break to the full, I have implemented a module that at runtime modifies the io server to send copies of all requests to a specified process.
The implementation uses Smerl (thanks Yariv! ) and will be included in Erlide.
Usage:
*stdio_handler:install(Handler) when is_atom(Handler)
Handler has to be a process' name because we can't get an abstract form for pids...
*stdio_handler:uninstall()
We change the second clause of io:request/2 from
Code: request(Pid, Request) when pid(Pid) ->
Mref = erlang:monitor(process,Pid),
Pid ! {io_request,self(),Pid,io_request(Pid, Request)},
wait_io_mon_reply(Pid,Mref);
with
Code: request(Pid, Request) when pid(Pid) ->
case proccess_info(Pid, group_leader} of
{group_leader, Pid} ->
catch *Handler* ! {request, Pid, Request, self(), erlang:now()};
_ ->
ok
end,
Mref = erlang:monitor(process,Pid),
Pid ! {io_request,self(),Pid,io_request(Pid, Request)},
wait_io_mon_reply(Pid,Mref);
We only want to capture standard_io output, i.e. where the group_leader is its own group_leader. So now your process will get notified when something gets read or written.
Of course, this is very brittle (changing io:request/2 might break everything), but I can live with it.
best regards,
Vlad |
| Description: |
|
 Download |
| Filename: |
stdio_handler.erl |
| Filesize: |
2.12 KB |
| Downloaded: |
1466 Time(s) |
|
|
| Back to top |
|
| lokifirebringer |
Posted: Mon Aug 03, 2009 9:52 pm |
|
|
|
Joined: 29 Jul 2009
Posts: 9
|
| I'm confused on how to get this to work; could you show an example? |
|
|
|
| Back to top |
|
| vladdu |
Posted: Fri Aug 21, 2009 6:50 am |
|
|
|
User
Joined: 28 Feb 2005
Posts: 397
Location: Gothenburg, Sweden
|
Hi!
stdio_handler was a quick hack, it worked until the next Erlang version only because it depends on the exact code in the io module.
We are using a "normal" remote shell now, with the disadvantage that output that goes directly to stdout must be caught in a different way (by watching the file descriptor, if available).
Another solution (untested) is to use an undocumented (and probably unsupported) option
> erl -user myuser
that lets you replace the 'user' process with your own implementation of an io server (see the user.erl module for reference). This way you can do whatever you want with the output data. The only data you can't catch that way is that written with erlang:display().
I hope this helps.
best regards,
Vlad |
|
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|
|