Execute Bash Program Using Js

[Solved] Execute Bash Program Using Js | Perl - Code Explorer | yomemimo.com
Question : how to run a bash script with node js

Answered by : anthony-smith

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);
});

Source : https://medium.com/stackfame/how-to-run-shell-script-file-or-command-using-nodejs-b9f2455cb6b7 | Last Update : Tue, 22 Mar 22

Question : execute bash program using js

Answered by : blueeyed-bug-fdrxubjlrmm5

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');

Source : https://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript#comment46890340_1880198 | Last Update : Thu, 18 Nov 21

Answers related to execute bash program using js

Code Explorer Popular Question For Perl