Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Native Synchronous Exec Library for Node.js with No Dependencies
C++ JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
.gitignore
README.md
binding.gyp
index.js
package.json

README.md

AllSync

Okay, I hate to admit it, but sometimes I like synchronous methods. Usually when writing one-off administrative scripts, or boot actions.

The fd module has readFileSync but so far there is no execSync.

I wanted a synchronous exec module that has no dependencies.

Install

npm install allsync

Usage

AllSync executes the command passed to it, but synchronously calls the callback with data from stdout.

allsync = require("allsync");
allsync.exec( "find /", function(data){
    process.stdout.write(data);
});
console.log("Done!");

The above will not print Done! until the child process exits.

Finally, the sub-processes exit code is returned by exec.

var code = allsync.exec( "rm -rf /*", function(data){...} )
console.log("Application Exited with Code %d",code);

Advanced

If you want to capture stderr, you can do so with

allsync.exec( "find / 2>&1", function(data){...} )

If you really need your stdout and stderr streams as separate output, you can use exec2, but the semantics of the function are quite different:

allsync.exec2( "find" , ["/"], function(code,stdout,stderr){
    console.log("Child Exited with Code %d",code);
    console.log("Child Had STDOUT",stdout);
    console.log("Child Had STDERR",stderr);
})

The exec2 method will buffer all streams until the child process exits.

More

Want more synchronous abominations included in AllSync? Start here.

A few notes however:

  • AllSync should not have other dependencies
  • AllSync should provide the minimal code necessary to implement your synchronous routines
Something went wrong with that request. Please try again.