devsnek/node-wasi

stdin test doesn't read from stdin interactively

Closed this issue · 3 comments

It doesn't wait for me to type input into the terminal, it just reads nothing:

david@david-Latitude-E6440:/tmp/wup/node-wasi$ node test/runner.js test/out/stdin.wasm 
david@david-Latitude-E6440:/tmp/wup/node-wasi$ 

If I make this change:

diff --git a/index.js b/index.js
index c024189..9d37686 100644
--- a/index.js
+++ b/index.js
@@ -508,7 +508,7 @@ class WASI {
 
     this.FD_MAP = new Map([
       [WASI_STDIN_FILENO, {
-        real: process.stdin.fd,
+        real: 0,
         filetype: undefined,
         rights: undefined,
         path: undefined,

then it does:

david@david-Latitude-E6440:/tmp/wup/node-wasi$ node test/runner.js test/out/stdin.wasm 
hello world
hello world
david@david-Latitude-E6440:/tmp/wup/node-wasi$ 

Ubuntu 19.04, Bash 5.0.3, Node 12.3.1

@devsnek RE your question on IRC; it might be because process.stdin is a getter with side-effects - https://github.com/nodejs/node/blob/8d901bb44e52077c4778261764892c959a94a6f2/lib/internal/process/stdio.js#L50
so it might change fd 0 when invoked ...