'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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source