node helper to execute shell commands
See the codeExecute shell command forwarding all stdio streams.
exec-sh is a wrapper for child_process.spawn with some improvements:
cmd /C COMMANDsh -c COMMANDexecSh("bash")execsh("echo -n Say: && read i && echo Said:$i")execSh("pwd", console.log)// JavaScript
execSh("echo hello exec-sh && bash", { cwd: "/home" }, function(err){
if (err) {
console.log("Exit code: ", err.code);
}
});
# Terminal output: interactive bash session
hello exec-sh
bash-3.2$ pwd
/home
bash-3.2$ exit 99
exit
Exit code: 99
const execSh = require("../");
// run interactive bash shell
execSh("echo lorem && bash", { cwd: "/home" }, (err) => {
if (err) {
console.log("Exit code: ", err.code);
return;
}
// collect streams output
const child = execSh(["bash -c id", "echo lorem >&2"], true,
(err, stdout, stderr) => {
console.log("error: ", err);
console.log("stdout: ", stdout);
console.log("stderr: ", stderr);
});
});
const execShPromise = require("exec-sh").promise;
// run interactive bash shell
const run = async () => {
let out;
try {
out = await execShPromise('pwd', true);
} catch (e) {
console.log('Error: ', e);
console.log('Stderr: ', e.stderr);
console.log('Stdout: ', e.stdout);
return e;
}
console.log('out: ', out.stdout, out.stderr);
}
run();
execSh(command, [options], [callback])Execute shell command forwarding all stdio.
Parameters:
command {String|Array} - The command to run, or array of commands[options] {Object|TRUE} - Options object passed directly to child_process.spawn, when TRUE then { stdio: null } used[callback] {Function} - callback(err, stdout, stderr)err {Error|NULL} - Error object. Has code property containing last command exit code when availablestdout {String|NULL} - aggregated stdout or NULL if not availablestderr {String|NULL} - aggregated stderr or NULL if not availableReturn Values:
Returns ChildProcess object.
npm test - run testsnpm run jsdoc - build jsdocnpm run dev - run tests continuouslyThe MIT License (MIT)
Overall
Maintained
Code review
npm
Latest release
Releases this year
node helper to execute shell commands
See the codeExecute shell command forwarding all stdio streams.
exec-sh is a wrapper for child_process.spawn with some improvements:
cmd /C COMMANDsh -c COMMANDexecSh("bash")execsh("echo -n Say: && read i && echo Said:$i")execSh("pwd", console.log)// JavaScript
execSh("echo hello exec-sh && bash", { cwd: "/home" }, function(err){
if (err) {
console.log("Exit code: ", err.code);
}
});
# Terminal output: interactive bash session
hello exec-sh
bash-3.2$ pwd
/home
bash-3.2$ exit 99
exit
Exit code: 99
const execSh = require("../");
// run interactive bash shell
execSh("echo lorem && bash", { cwd: "/home" }, (err) => {
if (err) {
console.log("Exit code: ", err.code);
return;
}
// collect streams output
const child = execSh(["bash -c id", "echo lorem >&2"], true,
(err, stdout, stderr) => {
console.log("error: ", err);
console.log("stdout: ", stdout);
console.log("stderr: ", stderr);
});
});
const execShPromise = require("exec-sh").promise;
// run interactive bash shell
const run = async () => {
let out;
try {
out = await execShPromise('pwd', true);
} catch (e) {
console.log('Error: ', e);
console.log('Stderr: ', e.stderr);
console.log('Stdout: ', e.stdout);
return e;
}
console.log('out: ', out.stdout, out.stderr);
}
run();
execSh(command, [options], [callback])Execute shell command forwarding all stdio.
Parameters:
command {String|Array} - The command to run, or array of commands[options] {Object|TRUE} - Options object passed directly to child_process.spawn, when TRUE then { stdio: null } used[callback] {Function} - callback(err, stdout, stderr)err {Error|NULL} - Error object. Has code property containing last command exit code when availablestdout {String|NULL} - aggregated stdout or NULL if not availablestderr {String|NULL} - aggregated stderr or NULL if not availableReturn Values:
Returns ChildProcess object.
npm test - run testsnpm run jsdoc - build jsdocnpm run dev - run tests continuouslyThe MIT License (MIT)
Overall
Maintained
Code review
npm
Latest release
Releases this year