erlectricity-funbox 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/History.txt +35 -0
- data/LICENSE +20 -0
- data/README.md +130 -0
- data/Rakefile +74 -0
- data/VERSION.yml +4 -0
- data/benchmarks/bench.rb +21 -0
- data/erlectricity.gemspec +105 -0
- data/examples/echo/README.md +12 -0
- data/examples/echo/echo.erl +13 -0
- data/examples/echo/echo.rb +11 -0
- data/examples/gruff/gruff.erl +61 -0
- data/examples/gruff/gruff_provider.rb +31 -0
- data/examples/gruff/gruff_run.sh +19 -0
- data/examples/gruff/stat_run.sh +20 -0
- data/examples/gruff/stat_writer.erl +40 -0
- data/examples/simple/README.md +5 -0
- data/examples/simple/rerl.rb +111 -0
- data/examples/simple/rerl.sh +37 -0
- data/examples/tinderl/README.md +14 -0
- data/examples/tinderl/tinderl.erl +43 -0
- data/examples/tinderl/tinderl.rb +28 -0
- data/ext/decoder.c +398 -0
- data/ext/extconf.rb +11 -0
- data/lib/erlectricity.rb +33 -0
- data/lib/erlectricity/condition.rb +66 -0
- data/lib/erlectricity/conditions/boolean.rb +11 -0
- data/lib/erlectricity/conditions/hash.rb +13 -0
- data/lib/erlectricity/conditions/static.rb +34 -0
- data/lib/erlectricity/conditions/type.rb +17 -0
- data/lib/erlectricity/constants.rb +36 -0
- data/lib/erlectricity/decoder.rb +212 -0
- data/lib/erlectricity/encoder.rb +164 -0
- data/lib/erlectricity/errors/decode_error.rb +3 -0
- data/lib/erlectricity/errors/encode_error.rb +3 -0
- data/lib/erlectricity/errors/erlectricity_error.rb +3 -0
- data/lib/erlectricity/matcher.rb +21 -0
- data/lib/erlectricity/port.rb +46 -0
- data/lib/erlectricity/receiver.rb +69 -0
- data/lib/erlectricity/types/function.rb +3 -0
- data/lib/erlectricity/types/list.rb +3 -0
- data/lib/erlectricity/types/new_function.rb +3 -0
- data/lib/erlectricity/types/new_reference.rb +3 -0
- data/lib/erlectricity/types/pid.rb +3 -0
- data/lib/erlectricity/types/reference.rb +3 -0
- data/lib/erlectricity/version.rb +9 -0
- data/test/condition_spec.rb +72 -0
- data/test/decode_spec.rb +145 -0
- data/test/encode_spec.rb +146 -0
- data/test/matcher_spec.rb +81 -0
- data/test/port_spec.rb +34 -0
- data/test/receiver_spec.rb +103 -0
- data/test/spec_suite.rb +2 -0
- data/test/test_helper.rb +46 -0
- metadata +116 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
pkg
|
2
|
+
ext/Makefile
|
3
|
+
ext/decoder.bundle
|
4
|
+
ext/decoder.o
|
5
|
+
*.beam
|
6
|
+
*.dump
|
7
|
+
.DS_Store
|
8
|
+
*.gem
|
9
|
+
*.rbc
|
10
|
+
.bundle
|
11
|
+
.config
|
12
|
+
.yardoc
|
13
|
+
Gemfile.lock
|
14
|
+
InstalledFiles
|
15
|
+
_yardoc
|
16
|
+
coverage
|
17
|
+
doc/
|
18
|
+
lib/bundler/man
|
19
|
+
pkg
|
20
|
+
rdoc
|
21
|
+
spec/reports
|
22
|
+
test/tmp
|
23
|
+
test/version_tmp
|
24
|
+
tmp
|
data/History.txt
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
== 1.1.1 / 2009-10-28
|
2
|
+
* Bug Fixes
|
3
|
+
* Fix bignum encoding
|
4
|
+
* Prevent stack overflow for massive binaries in c decoder
|
5
|
+
* Optimize strings in c decoder
|
6
|
+
|
7
|
+
== 1.1.0 / 2009-10-08
|
8
|
+
* Minor Improvements
|
9
|
+
* Implement Bignum encoding
|
10
|
+
* Fix tests on Erlang R13B
|
11
|
+
|
12
|
+
== 1.0.2 / 2009-06-03
|
13
|
+
* Bug Fixes
|
14
|
+
* Fix decoding of atoms [github.com/bwbuchanan]
|
15
|
+
* Work around Ruby's reluctance to convert the empty string to
|
16
|
+
a symbol [github.com/bwbuchanan]
|
17
|
+
|
18
|
+
== 1.0.1 / 2009-05-03
|
19
|
+
* Bug Fixes
|
20
|
+
* Fix premature null byte termination on binary decode
|
21
|
+
|
22
|
+
== 1.0.0 / 2009-04-29
|
23
|
+
* Backward Incompatible Changes
|
24
|
+
* Implicit array call for f.when(:echo, String) must now be called as
|
25
|
+
f.when([:echo, String]) to eliminate ambiguity
|
26
|
+
* Implicit array call for f.send!(:ok, "foo") must now be called as
|
27
|
+
f.send!([:ok, "foo"]) to eliminate ambiguity
|
28
|
+
* The receive loop now defaults to using file descriptors 3 and 3
|
29
|
+
instead of STDIN and STDOUT. This prevents inadvertent output
|
30
|
+
statements from silently corrupting the transfer protocol.
|
31
|
+
* Erlang atoms 'true' and 'false' are now converted into Ruby booleans
|
32
|
+
* Erlectricity::Decoder.read_any_from -> Erlectricity::Decoder.decode
|
33
|
+
* Major Enhancements
|
34
|
+
* Calling `rake` now runs tests (with and without compiled C extensions)
|
35
|
+
* Package management is now done by Jeweler
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Scott Fleckenstein and Tom Preston-Werner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
Erlectricity
|
2
|
+
============
|
3
|
+
|
4
|
+
http://github.com/mojombo/erlectricity
|
5
|
+
|
6
|
+
By Scott Fleckenstein, Tom Preston-Werner
|
7
|
+
|
8
|
+
Development Status: Production/Stable
|
9
|
+
|
10
|
+
|
11
|
+
Description
|
12
|
+
-----------
|
13
|
+
|
14
|
+
Erlectricity allows a Ruby program to receive and respond to Erlang messages
|
15
|
+
sent over the Erlang binary protocol.
|
16
|
+
|
17
|
+
|
18
|
+
Install
|
19
|
+
-------
|
20
|
+
|
21
|
+
$ gem install erlectricity
|
22
|
+
|
23
|
+
-or-
|
24
|
+
|
25
|
+
$ gem install mojombo-erlectricity -s http://gems.github.com
|
26
|
+
|
27
|
+
|
28
|
+
The Simplest Example
|
29
|
+
--------------------
|
30
|
+
|
31
|
+
### Ruby side (echo.rb)
|
32
|
+
|
33
|
+
require 'rubygems'
|
34
|
+
require 'erlectricity'
|
35
|
+
|
36
|
+
receive do |f|
|
37
|
+
f.when([:echo, String]) do |text|
|
38
|
+
f.send!([:result, "You said: #{text}"])
|
39
|
+
f.receive_loop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
### Erlang side (echo.erl)
|
44
|
+
|
45
|
+
-module(echo).
|
46
|
+
-export([test/0]).
|
47
|
+
|
48
|
+
test() ->
|
49
|
+
Cmd = "ruby echo.rb",
|
50
|
+
Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio, exit_status, binary]),
|
51
|
+
Payload = term_to_binary({echo, <<"hello world!">>}),
|
52
|
+
port_command(Port, Payload),
|
53
|
+
receive
|
54
|
+
{Port, {data, Data}} ->
|
55
|
+
{result, Text} = binary_to_term(Data),
|
56
|
+
io:format("~p~n", [Text])
|
57
|
+
end.
|
58
|
+
|
59
|
+
|
60
|
+
Data Type Conversions and Matching
|
61
|
+
----------------------------------
|
62
|
+
|
63
|
+
% Port is the port opened via open_port({spawn, Cmd}, [{packet, 4}, ...])
|
64
|
+
% Message is the Erlang term to encode and send to the port
|
65
|
+
send(Port, Message) ->
|
66
|
+
port_command(Port, term_to_binary(Message)).
|
67
|
+
|
68
|
+
# Each triplet below represents:
|
69
|
+
# (line 1) the Erlang call
|
70
|
+
# (line 2) the Ruby matcher
|
71
|
+
# (line 3) the Ruby output
|
72
|
+
|
73
|
+
send(Port, test).
|
74
|
+
f.when(:test) { p :ok }
|
75
|
+
# :ok
|
76
|
+
|
77
|
+
send(Port, {atom, symbol}).
|
78
|
+
f.when([:atom, Symbol]) { |sym| p sym }
|
79
|
+
# :symbol
|
80
|
+
|
81
|
+
send(Port, {number, 1}).
|
82
|
+
f.when([:number, Fixnum]) { |num| p num }
|
83
|
+
# 1
|
84
|
+
|
85
|
+
send(Port, {string, <<"foo">>}).
|
86
|
+
f.when([:string, String]) { |str| p str }
|
87
|
+
# "foo"
|
88
|
+
|
89
|
+
send(Port, {array, [1,2,3]}).
|
90
|
+
f.when([:array, Array]) { |arr| p arr }
|
91
|
+
# [1, 2, 3]
|
92
|
+
|
93
|
+
send(Port, {array, [<<"abc">>, <<"def">>]}).
|
94
|
+
f.when([:array, Array]) { |arr| p arr }
|
95
|
+
# ["abc", "def"]
|
96
|
+
|
97
|
+
send(Port, {hash, [{key,val}]}).
|
98
|
+
f.when([:hash, Erl.hash]) { |hash| p hash }
|
99
|
+
# {:key=>:val}
|
100
|
+
|
101
|
+
send(Port, {object, {1,{2},3,<<"four">>}}).
|
102
|
+
f.when([:object, Any]) { |any| p any }
|
103
|
+
# [1, [2], 3, "four"]
|
104
|
+
|
105
|
+
|
106
|
+
Contribute
|
107
|
+
----------
|
108
|
+
|
109
|
+
If you'd like to hack on Erlectricity, start by forking my repo on GitHub:
|
110
|
+
|
111
|
+
http://github.com/mojombo/erlectricity
|
112
|
+
|
113
|
+
To get all of the dependencies, install the gem first. The best way to get
|
114
|
+
your changes merged back into core is as follows:
|
115
|
+
|
116
|
+
1. Clone down your fork
|
117
|
+
1. Create a topic branch to contain your change
|
118
|
+
1. Hack away
|
119
|
+
1. Add tests and make sure everything still passes by running `rake`
|
120
|
+
1. If you are adding new functionality, document it in the README.md
|
121
|
+
1. Do not change the version number, I will do that on my end
|
122
|
+
1. If necessary, rebase your commits into logical chunks, without errors
|
123
|
+
1. Push the branch up to GitHub
|
124
|
+
1. Send me (mojombo) a pull request for your branch
|
125
|
+
|
126
|
+
|
127
|
+
Copyright
|
128
|
+
---------
|
129
|
+
|
130
|
+
Copyright (c) 2009 Scott Fleckenstein and Tom Preston-Werner. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "erlectricity"
|
8
|
+
gem.rubyforge_project = "erlectricity"
|
9
|
+
gem.summary = "A library to interface erlang and ruby through the erlang port system"
|
10
|
+
gem.email = "tom@mojombo.com"
|
11
|
+
gem.homepage = "http://github.com/mojombo/erlectricity"
|
12
|
+
gem.authors = ["Scott Fleckenstein", "Tom Preston-Werner"]
|
13
|
+
gem.require_paths = ["lib", "ext"]
|
14
|
+
gem.files.include("ext")
|
15
|
+
gem.extensions << 'ext/extconf.rb'
|
16
|
+
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
task :test do
|
24
|
+
require 'open3'
|
25
|
+
require 'fileutils'
|
26
|
+
|
27
|
+
puts "\nCleaning extension build files and running all specs in native ruby mode..."
|
28
|
+
`rm -f ext/*.bundle` && puts("rm -f ext/*.bundle")
|
29
|
+
`rm -f ext/*.o` && puts("rm -f ext/*.o")
|
30
|
+
Open3.popen3("ruby test/spec_suite.rb") do |stdin, stdout, stderr|
|
31
|
+
while !stdout.eof?
|
32
|
+
print stdout.read(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
puts "\nRunning `make` to build extensions and rerunning decoder specs..."
|
37
|
+
Dir.chdir('ext') { `make` }
|
38
|
+
Open3.popen3("ruby test/decode_spec.rb") do |stdin, stdout, stderr|
|
39
|
+
while !stdout.eof?
|
40
|
+
print stdout.read(1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'rcov/rcovtask'
|
47
|
+
Rcov::RcovTask.new do |test|
|
48
|
+
test.libs << 'test'
|
49
|
+
test.pattern = 'test/**/*_test.rb'
|
50
|
+
test.verbose = true
|
51
|
+
end
|
52
|
+
rescue LoadError
|
53
|
+
task :rcov do
|
54
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
task :default => :test
|
60
|
+
|
61
|
+
require 'rake/rdoctask'
|
62
|
+
Rake::RDocTask.new do |rdoc|
|
63
|
+
if File.exist?('VERSION.yml')
|
64
|
+
config = YAML.load(File.read('VERSION.yml'))
|
65
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
66
|
+
else
|
67
|
+
version = ""
|
68
|
+
end
|
69
|
+
|
70
|
+
rdoc.rdoc_dir = 'rdoc'
|
71
|
+
rdoc.title = "erlectricity #{version}"
|
72
|
+
rdoc.rdoc_files.include('README*')
|
73
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
74
|
+
end
|
data/VERSION.yml
ADDED
data/benchmarks/bench.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'erlectricity'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
data = [:ok, [:foo, :bar, [99, "bottles", "of", "beer", 3.14], [true, false]]]
|
7
|
+
bert = Erlectricity::Encoder.encode(data)
|
8
|
+
|
9
|
+
p bert
|
10
|
+
|
11
|
+
Benchmark.bm do|b|
|
12
|
+
b.report("Decoder") do
|
13
|
+
100_000.times { Erl::Decoder.decode(bert) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# user system total real
|
18
|
+
# C Decoder 0.400000 0.000000 0.400000 ( 0.425373)
|
19
|
+
# Ruby Decoder 30.250000 0.220000 30.470000 ( 32.140890)
|
20
|
+
#
|
21
|
+
# C decoder is 75.56x faster than Ruby decoder on this data
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{erlectricity-funbox}
|
8
|
+
s.version = "1.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Scott Fleckenstein", "Tom Preston-Werner"]
|
12
|
+
s.date = %q{2009-10-28}
|
13
|
+
s.email = %q{tom@mojombo.com}
|
14
|
+
s.extensions = ["ext/extconf.rb"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"History.txt",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"benchmarks/bench.rb",
|
27
|
+
"erlectricity.gemspec",
|
28
|
+
"examples/echo/README.md",
|
29
|
+
"examples/echo/echo.erl",
|
30
|
+
"examples/echo/echo.rb",
|
31
|
+
"examples/gruff/gruff.erl",
|
32
|
+
"examples/gruff/gruff_provider.rb",
|
33
|
+
"examples/gruff/gruff_run.sh",
|
34
|
+
"examples/gruff/stat_run.sh",
|
35
|
+
"examples/gruff/stat_writer.erl",
|
36
|
+
"examples/simple/README.md",
|
37
|
+
"examples/simple/rerl.rb",
|
38
|
+
"examples/simple/rerl.sh",
|
39
|
+
"examples/tinderl/README.md",
|
40
|
+
"examples/tinderl/tinderl.erl",
|
41
|
+
"examples/tinderl/tinderl.rb",
|
42
|
+
"ext/decoder.c",
|
43
|
+
"ext/extconf.rb",
|
44
|
+
"lib/erlectricity.rb",
|
45
|
+
"lib/erlectricity/condition.rb",
|
46
|
+
"lib/erlectricity/conditions/boolean.rb",
|
47
|
+
"lib/erlectricity/conditions/hash.rb",
|
48
|
+
"lib/erlectricity/conditions/static.rb",
|
49
|
+
"lib/erlectricity/conditions/type.rb",
|
50
|
+
"lib/erlectricity/constants.rb",
|
51
|
+
"lib/erlectricity/decoder.rb",
|
52
|
+
"lib/erlectricity/encoder.rb",
|
53
|
+
"lib/erlectricity/errors/decode_error.rb",
|
54
|
+
"lib/erlectricity/errors/encode_error.rb",
|
55
|
+
"lib/erlectricity/errors/erlectricity_error.rb",
|
56
|
+
"lib/erlectricity/matcher.rb",
|
57
|
+
"lib/erlectricity/port.rb",
|
58
|
+
"lib/erlectricity/receiver.rb",
|
59
|
+
"lib/erlectricity/types/function.rb",
|
60
|
+
"lib/erlectricity/types/list.rb",
|
61
|
+
"lib/erlectricity/types/new_function.rb",
|
62
|
+
"lib/erlectricity/types/new_reference.rb",
|
63
|
+
"lib/erlectricity/types/pid.rb",
|
64
|
+
"lib/erlectricity/types/reference.rb",
|
65
|
+
"lib/erlectricity/version.rb",
|
66
|
+
"test/condition_spec.rb",
|
67
|
+
"test/decode_spec.rb",
|
68
|
+
"test/encode_spec.rb",
|
69
|
+
"test/matcher_spec.rb",
|
70
|
+
"test/port_spec.rb",
|
71
|
+
"test/receiver_spec.rb",
|
72
|
+
"test/spec_suite.rb",
|
73
|
+
"test/test_helper.rb"
|
74
|
+
]
|
75
|
+
s.homepage = %q{http://github.com/mojombo/erlectricity}
|
76
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
77
|
+
s.require_paths = ["lib", "ext"]
|
78
|
+
s.rubyforge_project = %q{erlectricity}
|
79
|
+
s.rubygems_version = %q{1.3.5}
|
80
|
+
s.summary = %q{A library to interface erlang and ruby through the erlang port system}
|
81
|
+
s.test_files = [
|
82
|
+
"test/condition_spec.rb",
|
83
|
+
"test/decode_spec.rb",
|
84
|
+
"test/encode_spec.rb",
|
85
|
+
"test/matcher_spec.rb",
|
86
|
+
"test/port_spec.rb",
|
87
|
+
"test/receiver_spec.rb",
|
88
|
+
"test/spec_suite.rb",
|
89
|
+
"test/test_helper.rb",
|
90
|
+
"examples/echo/echo.rb",
|
91
|
+
"examples/gruff/gruff_provider.rb",
|
92
|
+
"examples/simple/rerl.rb",
|
93
|
+
"examples/tinderl/tinderl.rb"
|
94
|
+
]
|
95
|
+
|
96
|
+
if s.respond_to? :specification_version then
|
97
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
98
|
+
s.specification_version = 3
|
99
|
+
|
100
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
101
|
+
else
|
102
|
+
end
|
103
|
+
else
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
This is a simple echo server example showing off basic Erlectricity usage.
|
2
|
+
|
3
|
+
$ cd examples/echo
|
4
|
+
$ erl
|
5
|
+
Erlang (BEAM) emulator version 5.6.4 [source] [smp:2] [async-threads:0] [kernel-poll:false]
|
6
|
+
|
7
|
+
Eshell V5.6.4 (abort with ^G)
|
8
|
+
1> c(echo).
|
9
|
+
{ok,echo}
|
10
|
+
2> echo:test().
|
11
|
+
<<"You said: hello world!">>
|
12
|
+
ok
|
@@ -0,0 +1,13 @@
|
|
1
|
+
-module(echo).
|
2
|
+
-export([test/0]).
|
3
|
+
|
4
|
+
test() ->
|
5
|
+
Cmd = "ruby echo.rb",
|
6
|
+
Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio, exit_status, binary]),
|
7
|
+
Payload = term_to_binary({echo, <<"hello world!">>}),
|
8
|
+
port_command(Port, Payload),
|
9
|
+
receive
|
10
|
+
{Port, {data, Data}} ->
|
11
|
+
{result, Text} = binary_to_term(Data),
|
12
|
+
io:format("~p~n", [Text])
|
13
|
+
end.
|