Skip to content

Commit 2c46818

Browse files
Curtis J SchofieldCurtis J Schofield
authored andcommitted
modifications to avoid polluting output with stdout from node
1 parent a1c0af4 commit 2c46818

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

lib/execjs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Execjs do
3535

3636
try do
3737
port = Port.open({ :spawn_executable, command },
38-
[:stream, :in, :binary, :eof, :hide, { :args, [tmpfile] }])
38+
[:stream, :in, :binary,:nouse_stdio, :eof, :hide, { :args, [tmpfile] }])
3939

4040
extract_result(loop(port))
4141
after

priv/node_runner.js.eex

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
(function(program, runner) { runner(program); })(function() {
2-
return <%= source %>;
3-
}, function(program) {
4-
var result;
5-
try {
6-
result = program();
7-
try {
8-
if (result === undefined) {
9-
process.stdout.write('["ok"]');
10-
} else {
11-
process.stdout.write(JSON.stringify(['ok', result]));
12-
}
13-
} catch (err) {
14-
process.stdout.write('["err"]');
1+
const fs = require('fs');
2+
(function(program, runner) {
3+
runner(program);
4+
})(
5+
function() {
6+
return <%= source %>;
157
}
16-
} catch (err) {
17-
process.stdout.write(JSON.stringify(['err', '' + err]));
18-
}
19-
});
8+
, async function(program) {
9+
let result;
10+
try {
11+
result = await program();
12+
try {
13+
if (result === undefined) {
14+
fs.writeSync(4,'["ok"]');
15+
} else {
16+
fs.writeSync(4,JSON.stringify(['ok', result]));
17+
}
18+
} catch (err) {
19+
fs.writeSync(4, '["err"]');
20+
}
21+
} catch (err) {
22+
fs.writeSync(4,JSON.stringify(['err', '' + err]));
23+
}
24+
});

0 commit comments

Comments
 (0)