我将如何能够做到以下几点:
system.c
#include<stdio.h>
int main()
{
system("/home/noob/send.erl");
return(0);
}
来自使用 erlang 客户端rabbitmq-tutorials/erlang/的 RabbitMQ 教程
send.erl
#!/usr/bin/env escript
%%! -pz ./deps/amqp_client ./deps/rabbit_common ./deps/amqp_client/ebin ./deps/rabbit_common/ebin
-include_lib("deps/amqp_client/include/amqp_client.hrl").
main(_) ->
{ok, Connection} =
amqp_connection:start(#amqp_params_network{host = "localhost"}),
{ok, Channel} = amqp_connection:open_channel(Connection),
amqp_channel:call(Channel, #'queue.declare'{queue = <<"hello">>}),
amqp_channel:cast(Channel,
#'basic.publish'{
exchange = <<"">>,
routing_key = <<"hello">>},
#amqp_msg{payload = <<"Hello World!">>}),
io:format("[x] Sent 'Hello World!'~n"),
ok = amqp_channel:close(Channel),
ok = amqp_connection:close(Connection),
ok.
然后运行:
gcc system.c -o system
noob$./system
输出:
send.erl:20: can't find include lib "rabbit_common/include/rabbit.hrl"
send.erl:21: can't find include lib "rabbit_common/include/rabbit_framing.hrl"
escript: There were compilation errors.
所以我这样做amqp_client.hrl
-include_lib("../../rabbit_common/include/rabbit.hrl").
-include_lib("../../rabbit_common/include/rabbit_framing.hrl").
然后运行noob$./system
和繁荣:
escript: exception error: undefined function amqp_connection:start/1
in function erl_eval:do_apply/6 (erl_eval.erl, line 572)
in call from erl_eval:expr/5 (erl_eval.erl, line 367)
in call from escript:eval_exprs/5 (escript.erl, line 836)
in call from erl_eval:local_func/5 (erl_eval.erl, line 470)
in call from escript:interpret/4 (escript.erl, line 754)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_it/1
因此,escript 在编译时似乎存在 PATHS 问题,并且它在 C 的 system() 调用中被调用。
知道我将如何实现这一目标吗?
TIA