Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda