summaryrefslogtreecommitdiff
path: root/lib/erl_interface/doc/src/erl_call_cmd.xml
blob: 19b159d7a3a821981f13a91eaba09064f8515474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE comref SYSTEM "comref.dtd">

<comref>
  <header>
    <copyright>
      <year>1996</year><year>2017</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>erl_call</title>
    <prepared>Torbj&ouml;rn T&ouml;rnkvist</prepared>
    <responsible>Torbj&ouml;rn T&ouml;rnkvist</responsible>
    <docno></docno>
    <approved>Bjarne D&auml;cker</approved>
    <checked>Torbj&ouml;rn T&ouml;rnkvist</checked>
    <date>1997-05-16</date>
    <rev>B</rev>
    <file>erl_call.xml</file>
  </header>
  <com>erl_call</com>
  <comsummary>Call/start a distributed Erlang node.</comsummary>
  <description>
    <p><c>erl_call</c> makes it possible to start and/or
      communicate with a distributed Erlang node. It is built upon the
      <c>Erl_Interface</c> library as an example application.
      Its purpose is to use a Unix shell script to interact with a distributed
      Erlang node. It performs all communication with the Erlang
      <em>rex server</em>, using the standard Erlang RPC facility. It does not
      require any special software to be run at the Erlang target node.</p>

    <p>The main use is to either start a distributed Erlang node
      or to make an ordinary function call. However, it is also
      possible to pipe an Erlang module to <c>erl_call</c> and have
      it compiled, or to pipe a sequence of Erlang expressions to be evaluated
      (similar to the Erlang shell).</p>

    <p>Options, which cause <c>stdin</c> to be read, can be used
      with advantage,
      as scripts from within (Unix) shell scripts. Another nice use
      of <c>erl_call</c> could be from (HTTP) CGI-bin scripts.</p>
  </description>

  <funcs>
    <func>
      <name>erl_call &lt;options></name>
      <fsummary>Start/call Erlang.</fsummary>
      <desc>
        <p>Starts/calls Erlang.</p>
        <p>Each option flag is described below with its name, type, and
          meaning.</p>
        <taglist>
          <tag><c>-a [Mod [Fun [Args]]]]</c></tag>
          <item>
            <p>(<em>Optional.</em>) Applies the specified function
              and returns the result. <c>Mod</c> must be specified.
              However, <c>start</c> and <c>[]</c> are assumed for unspecified
              <c>Fun</c> and <c>Args</c>, respectively.
              <c>Args</c> is to be in the same format as for
              <seemfa marker="erts:erlang#apply/3">
              <c>erlang:apply/3</c></seemfa> in <c>ERTS</c>.</p>
            <p>Notice that this flag takes exactly one argument, so quoting
              can be necessary to group <c>Mod</c>,
              <c>Fun</c>, and <c>Args</c> in a manner
              dependent on the behavior of your command shell.</p>
          </item>
          <tag><c>-address [Hostname:]Port</c></tag>
          <item>
            <p>(One of <c>-n</c>, <c>-name</c>, <c>-sname</c> or
            <c>-address</c> is required.) <c>Hostname</c> is the
            hostname of the machine that is running the peer node that
            <c>erl_call</c> shall communicate with. The default
            hostname is the hostname of the local machine. <c>Port</c>
            is the port number of the node that <c>erl_call</c> shall
            communicate with. The <c>-address</c> flag cannot be
            combined with any of the flags <c>-n</c>, <c>-name</c>,
            <c>-sname</c> or <c>-s</c>.</p>
            <p>The <c>-address</c> flag is typically useful when one
            wants to call a node that is running on machine without an
            accessible <seecom marker="erts:epmd">epmd</seecom>
            instance.</p>
          </item>
          <tag><c>-c Cookie</c></tag>
          <item>
            <p>(<em>Optional.</em>) Use this option to specify a certain cookie.
              If no cookie is specified, the <c>~/.erlang.cookie</c>
              file is read and its content is used as cookie. The Erlang node
              we want to communicate with must have the same cookie.</p>
          </item>
          <tag><c>-d</c></tag>
          <item>
            <p>(<em>Optional.</em>) Debug mode. This causes all I/O to be output
              to the <c>~/.erl_call.out.Nodename</c> file, where
              <c>Nodename</c>
              is the node name of the Erlang node in question.</p>
          </item>
          <tag><c>-e</c></tag>
          <item>
            <p>(<em>Optional.</em>) Reads a sequence of Erlang expressions,
              separated by comma (,) and ended with a full stop (.), from
              <c>stdin</c> until EOF (Control-D). Evaluates the
              expressions and returns the result from the last expression.
              Returns <c>{ok,Result}</c> on success.</p>
          </item>
          <tag><c>-fetch_stdout</c></tag>
          <item>
            <p>
              (<em>Optional.</em>) Executes the code, specified with
              the <c>-a</c> or <c>-e</c> option, in a new process that
              has a <seemfa marker="erts:erlang#group_leader/0">group
              leader</seemfa> that forwards all stdout (standard
              output) data so that it is printed to stdout of the
              <c>erl_call</c> process. This means that stdout data
              that are written during the execution of the called code,
              by the code and by descendant processes, will be
              forwarded (given that the group leader has not been
              changed by a call to <seemfa
              marker="erts:erlang#group_leader/2"><c>erlang:group_leader/2</c></seemfa>).
            </p>
            <p>
              The printed data is UTF-8 encoded.
            </p>
            <p>
              This option is only relevant together with the option
              <c>-a</c> or <c>-e</c>.
            </p>
            <p>
              See the documentation of <seeguide
              marker="stdlib:io_protocol">the I/O protocol</seeguide>,
              for more information about the group leader concept.
            </p>
            <note>
              <p>
                This option only works when <c>erl_call</c> is
                interacting with a node with a version greater or equal
                to OTP-24.
              </p>
            </note>
          </item>
          <tag><c>-h HiddenName</c></tag>
          <item>
            <p>(<em>Optional.</em>) Specifies the name of the hidden node
              that <c>erl_call</c> represents.</p>
          </item>
          <tag><c>-m</c></tag>
          <item>
            <p>(<em>Optional.</em>) Reads an Erlang module from
              <c>stdin</c> and compiles it.</p>
          </item>
          <tag><c>-n Node</c></tag>
          <item>
            <p>(One of <c>-n</c>, <c>-name</c>, <c>-sname</c> or
            <c>-address</c> is required.)
              Has the same meaning as <c>-name</c> and can still be
              used for backward compatibility reasons.</p>
          </item>
          <tag><c>-name Node</c></tag>
          <item>
            <p>(One of <c>-n</c>, <c>-name</c>, <c>-sname</c> or
            <c>-address</c> is required.)
              <c>Node</c> is the name of the peer node to be
              started or communicated with. It is assumed that
              <c>Node</c> is started with
              <c>erl -name</c>, which means that fully
              qualified long node names are used. If option
              <c>-s</c> is specified, an Erlang node will (if
              necessary) be started with <c>erl -name</c>.</p>
          </item>
          <tag><c>-no_result_term</c></tag>
          <item>
            <p>(<em>Optional.</em>) Do not print the result term. This
            option is only relevant together with the options
            <c>-a</c> and <c>-e</c>.</p>
          </item>
          <tag><c>-q</c></tag>
          <item>
            <p>(<em>Optional.</em>) Halts the Erlang node specified
              with switch <c>-n</c>. This switch overrides switch <c>-s</c>.</p>
          </item>
          <tag><c>-r</c></tag>
          <item>
            <p>(<em>Optional.</em>) Generates a random name of the hidden node
              that <c>erl_call</c> represents.</p>
          </item>
	  <tag><c>-R</c></tag>
          <item>
            <p>(<em>Optional.</em>) Request a dynamic random name, of the hidden node
              that <c>erl_call</c> represents, from the peer node. Supported
	    since OTP 23. Prefer <c>-R</c> over <c>-r</c> when doing repeated
	    requests toward the same peer node.</p>
          </item>
          <tag><c>-s</c></tag>
          <item>
            <p>(<em>Optional.</em>) Starts a distributed Erlang node if
              necessary. This means that in a sequence of calls, where
              '<c>-s</c>' and '<c>-n Node</c>' are
              constant, only the first call starts the Erlang node. This makes
              the rest of the communication very fast. This flag is currently
              only available on Unix-like platforms (Linux, Mac OS X, Solaris,
              and so on).</p>
          </item>
          <tag><c>-sname Node</c></tag>
          <item>
            <p>(One of <c>-n</c>, <c>-name</c>, <c>-sname</c> or
            <c>-address</c> is required.)
              <c>Node</c> is the name of the peer node to be started
              or communicated with. It is assumed that <c>Node</c>
              is started with <c>erl -sname</c>, which means that
              short node names are used. If option <c>-s</c> is
              specified, an Erlang node is started (if necessary) with
              <c>erl -sname</c>.</p>
          </item>
          <tag><c>-timeout Seconds</c></tag>
          <item>
            <p>(<em>Optional.</em>) Aborts the <c>erl_call</c> process after
              the timeout expires. Note that this does not abort commands that
              have already been started with <c>-a</c>, <c>-e</c>, or similar.
            </p>
          </item>
          <tag><c>-v</c></tag>
          <item>
            <p>(<em>Optional.</em>) Prints a lot of <c>verbose</c>
              information. This is only useful for the developer and maintainer
              of <c>erl_call</c>.</p>
          </item>
          <tag><c>-x ErlScript</c></tag>
          <item>
            <p>(<em>Optional.</em>) Specifies another name of the Erlang
              startup script to be used. If not specified, the standard
              <c>erl</c> startup script is used.</p>
          </item>
        </taglist>
      </desc>
    </func>
  </funcs>

  <section>
    <title>Examples</title>
    <p>To start an Erlang node and call <c>erlang:time/0</c>:</p>

    <code type="none"><![CDATA[
erl_call -s -a 'erlang time' -n madonna
{18,27,34}
    ]]></code>

    <p>To terminate an Erlang node by calling
      <c>erlang:halt/0</c>:</p>

    <code type="none"><![CDATA[
erl_call -s -a 'erlang halt' -n madonna
    ]]></code>

    <p>To apply with many arguments:</p>

    <code type="none"><![CDATA[
erl_call -s -a 'lists seq [1,10]' -n madonna
    ]]></code>

    <p>To evaluate some expressions
      (<em>the input ends with EOF (Control-D)</em>):</p>

    <code type="none"><![CDATA[
erl_call -s -e -n madonna
statistics(runtime),
X=1,
Y=2,
{_,T}=statistics(runtime),
{X+Y,T}.
^D
{ok,{3,0}}
    ]]></code>

    <p>To compile a module and run it (<em>again, the input ends with EOF
      (Control-D)</em>):</p>
    <p>(In the example, the output has been formatted afterwards.)</p>

    <code type="none"><![CDATA[
erl_call -s -m -a procnames -n madonna
-module(procnames).
-compile(export_all).
start() ->
        P = processes(),
        F = fun(X) -> {X,process_info(X,registered_name)} end,
        lists:map(F,[],P).
^D
[{<madonna@chivas.du.etx.ericsson.se,0,0>,
                  {registered_name,init}},
 {<madonna@chivas.du.etx.ericsson.se,2,0>,
                  {registered_name,erl_prim_loader}},
 {<madonna@chivas.du.etx.ericsson.se,4,0>,
                  {registered_name,error_logger}},
 {<madonna@chivas.du.etx.ericsson.se,5,0>,
                  {registered_name,application_controller}},
 {<madonna@chivas.du.etx.ericsson.se,6,0>,
                  {registered_name,kernel}},
 {<madonna@chivas.du.etx.ericsson.se,7,0>,
                  []},
 {<madonna@chivas.du.etx.ericsson.se,8,0>,
                  {registered_name,kernel_sup}},
 {<madonna@chivas.du.etx.ericsson.se,9,0>,
                  {registered_name,net_sup}},
 {<madonna@chivas.du.etx.ericsson.se,10,0>,
                  {registered_name,net_kernel}},
 {<madonna@chivas.du.etx.ericsson.se,11,0>,
                  []},
 {<madonna@chivas.du.etx.ericsson.se,12,0>,
                  {registered_name,global_name_server}},
 {<madonna@chivas.du.etx.ericsson.se,13,0>,
                  {registered_name,auth}},
 {<madonna@chivas.du.etx.ericsson.se,14,0>,
                  {registered_name,rex}},
 {<madonna@chivas.du.etx.ericsson.se,15,0>,
                  []},
 {<madonna@chivas.du.etx.ericsson.se,16,0>,
                  {registered_name,file_server}},
 {<madonna@chivas.du.etx.ericsson.se,17,0>,
                  {registered_name,code_server}},
 {<madonna@chivas.du.etx.ericsson.se,20,0>,
                  {registered_name,user}},
 {<madonna@chivas.du.etx.ericsson.se,38,0>,
                  []}]
   ]]></code>
    <p>To forward standard output without printing the result term
    (<em>again, the input ends with EOF (Control-D)</em>):</p>
    <code type="none"><![CDATA[
erl_call -s -e -sname madonna -fetch_stdout -no_result_term
io:format("Number of schedulers: ~p~n", [erlang:system_info(schedulers)]),
io:format("Number of logical cores: ~p~n", [erlang:system_info(logical_processors_available)]).
^D
Number of schedulers: 8
Number of logical cores: 8
    ]]></code>
  </section>
</comref>