You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Justine Kate Catid Miras 5ef3abc3c3 this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
..
example this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
lib this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
test this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
.jshintrc this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
.travis.yml this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
LICENSE this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
README.md this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago
package.json this is from the organization of my bootcamp repo which is mine that i did not notice i was not pushing it to my main repo, thats why i added this here and took me long cause i have no idea how to do this thanks to my curiosity i was able to identify or solve this problem. 10 months ago

README.md

exec-sh

NPM

NPM Downloads Build Status Coverage Status David Status

Execute shell command forwarding all stdio streams.

Features

exec-sh is a wrapper for child_process.spawn with some improvements:

  • Cross platform command execution:
    • Windows: cmd /C COMMAND
    • others: sh -c COMMAND
  • Fowrards all stdio streams to current terminal (by default):
    • execSh("bash")
    • execsh("echo -n Say: && read i && echo Said:$i")
  • stdout and stderr are passed to callback when available
    • execSh("pwd", console.log)

Showcase

// 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

Usage

var execSh = require("../");

// run interactive bash shell
execSh("echo lorem && bash", { cwd: "/home" }, function(err){
  if (err) {
    console.log("Exit code: ", err.code);
    return;
  }

  // collect streams output
  var child = execSh(["bash -c id", "echo lorem >&2"], true,
    function(err, stdout, stderr){
      console.log("error: ", err);
      console.log("stdout: ", stdout);
      console.log("stderr: ", stderr);
    });
});

Promise Interface

var 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();

Public API

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 available
  • stdout {String|NULL} - aggregated stdout or NULL if not available
  • stderr {String|NULL} - aggregated stderr or NULL if not available

Return Values:

Returns ChildProcess object.

Private API

Complete API Documentation including private and public methods is generated from source code by JSDoc tool and is available here.

Code Coverage

Code coverage report for all files is available here.

Scripts

  • npm test - run tests
  • npm run jsdoc - build jsdoc
  • npm run dev - run tests continuously

License

The MIT License (MIT)