Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

executive

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

executive

Elegant command execution.

  • 1.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-2.76%
Maintainers
1
Weekly downloads
 
Created
Source

executive Build Status Coverage Status NPM version Gitter chat

Greenkeeper badge

An elegant child_process.spawn. Automatically pipes stderr and stdout for you in a non-blocking fashion, making it very useful with build tools and task runners. Great async support with built-in serial and parallel command execution.

Features

  • Promise, Errback, and Synchronous APIs.
  • Serial execution by default with parallel execution optional.
  • Automatically pipes stderr and stdout by default.
  • Streams stderr and stdout rather than blocking on command completion.
  • Automatically uses shell when commands use operators or globs.
  • New-line delimited strings are automatically executed sequentially.
  • Easily blend commands, pure functions and promises with built-in control flow.

Install

$ npm install executive

Usage

No need to echo as stderr and stdout are piped by default.

var exec = require('executive');

exec('uglifyjs foo.js --compress --mangle > foo.min.js')

It's easy to be quiet too.

exec.quiet('uglifyjs foo.js --compress --mangle > foo.min.js')

Callbacks and promises are both supported.

exec('ls -l', (err, stdout, stderr) => {
    var files = stdout.split('\n');
})

exec('ls -l').then(res => {
    var files = res.stdout.split('\n');
})

Automatically serializes commands.

exec(['ls', 'ls', 'ls'], (err, stdout, stderr) => {
    // All three ls commands are called in order.
});

exec(`
ls
ls
ls`) // Same

Want to execute your commands in parallel? No problem.

exec.parallel(['ls', 'ls', 'ls'])

Want to blend in Promises or pure functions? No problem.

exec.parallel([
    'ls',

    // Promises can be blended directly in.
    exec('ls'),

    // Promises returned by functions are automatically consumed
    function() { return exec('ls') }),

    // Functions which return a string are assumed to be commands
    function() { return 'ls' },

    // Functions and promises can return objects with stdout, stderr or status
    function() { return {stdout: 'huzzah', stderr: '', status: 0} },

    'ls'
])

Options

Options are passed as the second argument to exec. Helper methods for quiet, interactive, parallel and sync do what you expect.

exec('ls', {options: quiet})

and

exec.quiet('ls')

are equivalent.

options.interactive | exec.interactive
default false

If you need to interact with a program (your favorite text editor for instance) or watch the output of a long running process (tail -f), or just don't care about checking stderr and stdout, set interactive to true:

exec.interactive('vim', err => {
    // Edit your commit message
});
options.quiet | exec.quiet
default false

If you'd prefer not to pipe stdout and stderr set quiet to true:

exec.quiet(['ls', 'ls'], (err, stdout, stderr) => {
    // You can still inspect stdout, stderr of course.
});
options.sync | exec.sync
default false

Blocking version of exec. Returns {stdout, stderr} or throws an error.

options.parallel | exec.parallel
default false

Uses parallel rather than serial execution of commands.

options.shell
default null

Force a shell to be used for command execution.

options.strict
default false

Any non-zero exit status is treated as an error. Promises will be rejected and an error will be thrown with exec.sync if syncThrows is enabled.

options.syncThrows
default false

Will cause exec.sync to throw errors rather than returning them.

Extra

Great with cake, grunt, gulp and other task runners. Even better mixed with generator-based control flow libraries and/or ES7 async/await.

Complex example using shortcake (which provides a superset of Cake's features, including generator/promise support):

require 'shortcake'

task 'package', 'Package project', ->
  await exec '''
    mkdir -p dist/
    rm   -rf dist/*
  '''

  await exec.parallel '''
    cp manifest.json dist/
    cp -rf assets/   dist/
    cp -rf lib/      dist/
    cp -rf views/    dist/
  '''

  await exec '''
    zip -r package.zip dist/
    rm -rf dist/
  '''

You can find more usage examples in the tests.

Keywords

FAQs

Package last updated on 20 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc