githubEdit

exec-sh

NPMarrow-up-right

NPM Downloadsarrow-up-right Build Statusarrow-up-right Coverage Statusarrow-up-right David Statusarrow-up-right

Execute shell command forwarding all stdio streams.

Features

exec-sh is a wrapper for child_process.spawnarrow-up-right 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);
  }
});

Usage

Promise Interface

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.spawnarrow-up-right, 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 ChildProcessarrow-up-right object.

Private API

Complete API Documentation including private and public methods is generated from source code by JSDoc tool and is available herearrow-up-right.

Code Coverage

Code coverage report for all files is available herearrow-up-right.

Scripts

  • npm test - run tests

  • npm run jsdoc - build jsdoc

  • npm run dev - run tests continuously

License

The MIT License (MIT)

Last updated

Was this helpful?