I'm doing a bash console using node.js. I have to use spawnSync instead of spawn. How do I make an event occur when a standard output occurs, capture it and send it to the client through a socket?
The code with spawn would be something like this:
var spawn = require('child_process').spawn;
var shell = spawn('/bin/bash');
shell.stdout.on('data', function(data) {
socket.emit('stdout', data);
});
socket.on('stdin', function(command) {
shell.stdin.write(command+"\n") || socket.emit('disable');
});
I need to know how to do something equivalent with spawnSync. If you need more code or clarify something, ask without fear.
Edit: for what Gustavo has explained, it is not viable to do it with spawnSync. Is there any way to know if a command has finished (correctly or incorrectly)? The fact is that there are commands like cd that do not emit output and I need a "something" (preferably an event) that tells me that it has ended.