[erlang-questions] Erlang shell command from Javascript (Electron) - Output Error
austin aigbe
eshikafe@REDACTED
Fri Oct 9 21:44:26 CEST 2015
Hello,
I am trying to call an Erlang module function from javascript but the
webpage does not display anything in the 'erl_ver' div element in the
index.html file.
--------------
index.html
---------------
<!DOCTYPE html>
<html>
<head>
<title>App</title>
</head>
<body>
<h1>Welcome to App</h1>
<div id='erl_ver'></div> <div id='electron_ver'></script>.
<script type="text/javascript">
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/')) + "/";
var e = require('child_process');
e.exec('erl -noshell -s shell_info get_ver -s erlang halt',{cwd: dir},
function(err,stdout, stderr) {
document.getElementById('erl_ver').innerHTML = "Erlang shell
version: " + stdout;
document.getElementById('electron_ver').innerHTML = ", Electron
version: " + process.versions['electron'];
});
</script>
</body>
</html>
-----------------
shell_info.erl
-----------------
-module(shell_info).-compile(export_all).
get_ver() ->
io:format(erlang:system_info(system_version)).
However, if I remove the cwd option from the javascript exec function, in
the index.html file, I get the following error on the webpage:
Erlang shell version: {"init terminating in
do_boot",{undef,[{shell_info,get_ver,[],[]},{init,start_it,1,[{file,"init.erl"},{line,1054}]},{init,start_em,1,[{file,"init.erl"},{line,1034}]}]}},
Electron version: 0.33.6
How do I display the expected shell_info:get_ver() output on the webpage?
Expected output:
C:\Users\eausaig\Downloads\electron-v0.33.6-win32-x64\erlang_studio>erl -noshell
-s shell_info get_ver -s erlang haltErlang/OTP 18 [erts-7.1] [64-bit]
[smp:4:4] [async-threads:10]
C:\Users\eausaig\Downloads\electron-v0.33.6-win32-x64\erlang_studio>
Regards,
Austin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151009/9daec5c4/attachment.htm>
More information about the erlang-questions
mailing list