Tuesday, 25 April 2017

How to ignore errors generated by child_process.exec?

I am executing shell script commands from my nodejs script. One of these commands is "npm install" followed by a command to run the index file of a nodejs file.

The npm install command is returning an error generated by node-gyp. In general, this error does not affect my service. However, child_process.exec is catching it and stopping the script. My questions is, how do I trigger the exec command and ignore the error returned?

Below is a fraction of the code snippet

const exec = require('child_process').exec;
exec("npm install", {
            cwd: serviceDirectory + gitRepo
        },
        (error1, stdout, stderr) => {
            if(error1){
                //this error is for testing purposes
                util.log(error1);
            }
            //run the service
            exec("node index.js",{
                cwd: serviceDirectory + gitRepo + "/"
            }, cb);

        });

}



via nicolas

No comments:

Post a Comment