I am running a Node.js script in Linux that prompts (via lib) user for a code. I get the process id of the script:
pgrep -f test.js
and then pass it the code with a new line to simulate Enter key:
echo -e "1234\n" > /proc/88888/fd/0
The code 1234
gets passed, a new line is added as well, but it didn't trigger Enter key and the script does not proceed. However, when I manually press Enter key in shell, the script does recognise the Enter key. So the question is how can I reliably send Enter key to another process/script?
Following is the code of test.js script:
inquirer = require('inquirer');
async function plztest() {
let { code } = await inquirer.prompt([
{
type: 'input',
name: 'code',
message: 'Enter code',
},
]);
console.log(code);
process.exit();
};
plztest();