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

170
Visualizações
Executing a shell script with interactions with child_processes in nodeJS

I am building a small custom node CLI application with user input using Inquirer and when after a specific chain of inputs, I would like to execute a script that has itself interactions as well. Right now I use the child_processes.exec() function to execute the command, which does work, however my terminal does not render the program and ends up stuck.

This code executes the external shell script:

cp.exec(
'svg-inliner', 
{
 cwd: iconsFolder, 
}, 
(err, stdout, stderr) => {
    if(err) throw err;
    if(stderr) {
      //...
       throw stderr;
    }
     if(stdout) return;
});

What it should do

What it currently does

Inquirer executes a callback once all the questions are answered from the termminal. Inside that callback I trigger a function that calls on the child_processes.exec().

inquirer.prompt(questions)
    .then(answers => {
      cp.exec();
    }

Is it actually possible to execute another CLI script from a Node.js CLI application?

Edit:

I created a .sh file that does what I wanted the exec to do. In that file I execute the node script followed by the svg-inliner command at works wonders.

node .index.js $1

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