Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

exec-sh

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Issues
File Explorer

Advanced tools

exec-sh

Execute shell command forwarding all stdio.

    0.4.0latest

Version published
Maintainers
1
Weekly downloads
8,634,270
decreased by-11.9%

Weekly downloads

Changelog

Source

  • Added typescript type declarations
  • var replaced with let and const

Readme

Source

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

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

Promise Interface

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

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)

Keywords

FAQs

What is exec-sh?

Execute shell command forwarding all stdio.

Is exec-sh popular?

The npm package exec-sh receives a total of 8,279,518 weekly downloads. As such, exec-sh popularity was classified as popular.

Is exec-sh well maintained?

We found that exec-sh demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 26 Mar 2021

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc