Chris Liaw
1 post
|
Hi,
After i read the book of Pragmatic Erlang, i got bought into the Erlang. However, since my previous project is all Java, i do have some Java library which is not available in Erlang such as complete cryptographic library.
I am pretty much wanted to use Erlang distributed, concurrency and fault torelant in my program but i also need the java cryptographic library. Hence i am thinking of creating a java program which is capable to be controlled by Erlang.
I tried the JInterface, it works but i am exploring to use Java port, which is the IO communication of Java program with Erlang node. However, i can not seems to get it working. Is there any specific steps which i need to do to allow Erlang can send and receive messages via open_port() with Java program?
Thanks.
Regards, Chris
|
Alain O'Dea
18 posts
|
If you use open_port({spawn, "command"}, [stream]) you will be able to use standard IO streams on the Java side and message send and receive operations on the Erlang side. There is also a line option which might be useful. Just make sure to use a PrintWriter or some other buffered output stream and call flush() from the Java side to send a message.
An Erlang module to dump content into the Mac OS X clipboard using the pbcopy program:
copy(Data) ->
Clipboard = open_port({spawn, "pbcopy"}, [stream]),
Clipboard ! {self(), {command, Data}},
Clipboard ! {self(), close},
receive
{Clipboard, closed} -> true
end.
If you bring up the Erlang docs for open_port on http://www.gotapi.com/ it explains how to communicate with the port.
|