简体   繁体   English

在已经运行的shell中通过控制台运行erlang shell命令

[英]Running erlang shell command, via console, in an already-running shell

Good morning ! 早上好 !

I'm trying to set up a communication between an erlang shell and an external function (zenity) that communicates only via scripts.(It can only run command lines) 我正在尝试在erlang shell和只通过脚本进行通信的外部函数(zenity)之间建立通信。(它只能运行命令行)

In my program, the erlang shell is already running and spawned nodes that I need. 在我的程序中,erlang shell已经运行并生成了我需要的节点。 (So opening an other shell to run the functions doesn't work, and escript opens a new shell. I need to run the functions from my main shell) (因此打开另一个shell来运行这些函数不起作用,并且escript打开一个新的shell。我需要从我的主shell运行这些函数)

This is what I manualy do, and would like to script it. 这就是我manualy所做的,并且想编写脚本。

$ erl -name two@127.0.0.1 
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
Eshell V7.3  (abort with ^G)
(two@127.0.0.1)1> c(client). 
{ok,client}
(two@127.0.0.1)2> client:init(). 
true
(two@127.0.0.1)3> 

The client:init() spawns threads. client:init()生成线程。 And I communicate with them via some functions. 我通过一些功能与他们沟通。

From here I run my different functions with 从这里开始我的不同功能

client:<function>(<Args>).

But a script whith 但是一个剧本

erl -name two@127.0.0.1
c(client).
client:init()
client:<function>(<Args>).

Obviously, it does not work. 显然,它不起作用。

I can shorten this a bit with 我可以稍微缩短一下

$ erl -name two@127.0.0.1 -s client init

But I still can't run functions on the shell that was created, because the function to call depends on the outputs of Zenity that only communicates via shell command lines 但我仍然无法在创建的shell上运行函数,因为要调用的函数取决于Zenity的输出,它只通过shell命令行进行通信

Are there solutions to run erlang command via a script ? 是否有通过脚本运行erlang命令的解决方案?

Why have you to run a command from zenity but not just grab result? 为什么要从zenity运行命令而不只是抓取结果? (Or you can run echo .) (或者你可以运行echo 。)

1> Port = open_port({spawn_executable, os:find_executable("zenity")}, [in, {line, 65536}, eof, {args, ["--calendar", "--title=Holiday Planner"]}]).
#Port<0.490> 
2> flush().
Shell got {#Port<0.490>,{data,{eol,"10/20/2016"}}}
Shell got {#Port<0.490>,eof}
ok

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM