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

151
Vistas
Can't run terminal commands with exec

i'm trying to use exec function in nodejs, but it's not working.

Here is the code that i'm runing :

import { exec } from "child_process";

exec("ssh ubuntu@myserverip", (error, stdout, stderr) => {
    if (error) {
        console.error(`error: ${error.message}`);
    }

    if (stderr) {
        console.error(`stderr: ${stderr}`);
    }

    else {
        console.log(`stdout:\n${stdout}`);
    }
});

And that it what it returns :

terminal

While this is the output if I directly write on terminal :

terminal

Any idea about how can I fix it ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use spawn, exec is used to execute commands whose result is going to be delivered to me immediately, or in a very short time, it has to be fast and where the output or the result that is going to be delivered to me is not very large, because exec creates a Buffer (a memory space) where it will start storing all the output of the command, and besides that it has a timeout, and if the command does not finish in that time it kills the process.

about 4 years ago · Juan Pablo Isaza 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