Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
¿Cómo saber si un proceso hijo ha terminado?

Trato de construir un terminal bash a través de la web con Node.js y socket.io, y necesito saber si un comando está terminado. Algunos comandos como 'cd someDirectory' no emiten una salida y no sé si terminó. ¿Cómo saber si un comando está terminado? ¿Si es posible establecer un tiempo de espera para cada comando? Tengo el siguiente código:

 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)); });

Gracias por adelantado.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

En general, el objeto spwan proporciona un evento de salida como se describe aquí . Crearía cada comando como spawn en lugar de usar write .

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

La segunda opción es verificar a través de pidof y pgrep si su proceso se está ejecutando o no.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!