Giter Club home page Giter Club logo

sync-exec's Introduction

sync-exec

An fs.execSync replacement until you get it natively from node 0.12+

Upgrading to 0.12.x is usually safe. At that point it will use child_process.execSync.

You can still force the emulated version passing {forceEmulated: true} to the options argument.

Advantages

Inspired by exec-sync but comes with a few advantages:

  • no libc requirement (no node-gyp compilation)
  • no external dependencies
  • returns the exit status code
  • you can pass execSync options
  • multiple commands should work pretty safely

Installation

[sudo] npm install sync-exec

Signature

exec(cmd[, timeout][, options]);

Examples

var exec = require('sync-exec');

// { stdout: '1\n',
//   stderr: '',
//   status: 0 }
console.log(exec('echo 1'));

// You can even pass options, just like for [child_process.exec](http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
console.log(exec('ls -la', {cwd: '/etc'}));

// Times out after 1 second, throws an error
exec('sleep 3; echo 1', 1000);

How it works (if you care)

Your commands STDOUT and STDERR outputs will be channeled to files, also the exit code will be saved. Synchronous file readers will start listening to these files right after. Once outputting is done, values get picked up, tmp files get deleted and values are returned to your code.

sync-exec's People

Contributors

ddsol avatar gvarsanyi avatar jamesmgreene avatar nessdan avatar tecfu avatar tedpennings avatar typicode avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.