Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
How to know if a child procces is finished?

I try to build a bash terminal via web with Node.js and socket.io, and I need know if a command is finished. Some command like 'cd someDirectory' don't emit a output and I don't know if it finished. How to know if a command if finished? If posible set a timeout for each command? I have the following code:

var shell = spawn('/bin/bash');
var stdin = shell.stdin;

shell.on('exit', function() {
  socket.disconnect();
});

shell.on('close',function(){
  console.log('Close');
});

shell['stdout'].setEncoding('ascii');
shell['stdout'].on('data', function(data) {
  socket.emit('stdout', data);
});

shell['stderr'].setEncoding('ascii');
shell['stderr'].on('data', function(data) {
  socket.emit('stderr', data);
});

socket.on('stdin', function(command) {
  stdin.write(command+"\n") || socket.emit('disable');
});

stdin.on('drain', function() {
   socket.emit('enable');
});

stdin.on('error', function(exception) {
  socket.emit('error', String(exception));
});

Thanks in advance.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

In general the spwan object provides an Exit event as is described here. I would create each command as spawn instead using write.

command.on('exit', function (code) {
  console.log('child process exited with code ' + code);
});

Second option is to check via pidof and pgrep whether your process is running or not.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda