I am experimenting with the code below, for testing how does child_process.exec() in node.js handle standard input from user.
import { exec } from 'child_process';
exec('powershell "$userInput = Read-Host;"', (err, stdout, stderr) => {
if(err) throw err;
console.log(stdout);
console.log(stderr);
});
When I ran this through node main.js
, the terminal is running forever with no output.
It seems that the exec() function creates a new shell waiting for user to type in it. However, I was unable to find the place to do so.
So I wonder if there are some ways to show that place or to handle this problem without the need to use Read-Host to receive user input.