Answers for "how to run a bash script with node js"

2

execute bash program using js

function exec(cmd, handler = function(error, stdout, stderr){console.log(stdout);if(error !== null){console.log(stderr)}})
{
    const childfork = require('child_process');
    return childfork.exec(cmd, handler);
}
exec('echo test');
Posted by: Guest on November-11-2021
0

how to run a bash script with node js

const exec = require('child_process').exec, child;
const myShellScript = exec('sh doSomething.sh /myDir');
myShellScript.stdout.on('data', (data)=>{
    console.log(data); 
    // do whatever you want here with data
});
myShellScript.stderr.on('data', (data)=>{
    console.error(data);
});
Posted by: Guest on March-15-2022

Code answers related to "how to run a bash script with node js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language