I am trying to send Enter
key to a child_process in Node.js. \r\n
, \n
, isn't actually sending the Enter
key to a Psy Shell (a PHP repl).
const execa = require("execa");
const { Readable } = require("stream");
const subprocess = execa("php", ["artisan", "tinker"], { cwd: "C:\\laravel-app" });
const str = Readable.from("5+5;\r\n2+2;"); // <-- Here
str.pipe(subprocess.stdin);
(async () => {
const a = await readableToString(subprocess.stdout);
const b = await readableToString(subprocess.stderr);
subprocess.kill();
console.log(a);
console.log(b);
})();
// This function turns a stream to a readable string
async function readableToString(readable) {
let result = "";
for await (const chunk of readable) {
result += chunk;
}
return result;
}
The output should be
10
4
Instead I'm getting
4
It's the same result I get when I input 5+5;2+2
in PsySh (in the terminal manually).