This command is giving my unit tests trouble. The problem is that the test gets stuck waiting for the child process to receive a newline:
var cmd = spawn('ls');
So, I send a newline, as advised in this thread:
setTimeout(function() {
cmd.stdin.write('\n');
console.log('Ending terminal session');
}, 2000);
I get this exception:
Error: This socket has been ended by the other party
at Socket.writeAfterFIN [as write] (net.js:275:12)
If I run the command from command line, as soon as I hit the enter key the function returns as expected, but it does not send the newline via stdin without the aforementioned error.