Git Product home page Git Product logo

runsync's Introduction

runsync

Polyfill of spawnSync and execSync for Node-0.10.x (Unix only yet)

Build Status Coverage Status

NPM

Instllation

Requires [node-gyp] (https://github.com/TooTallNate/node-gyp)

$ npm install runsync

Usage

var runsync = require("runsync");
var result = runsync.spawn("echo", ["Hello", "World!"], { encoding: "utf8" });
console.log(result.stdout); // => Hello world!\n

runsync.exec("sleep 1");

result = runsync.popen("echo Error message 1>&2", { encoding: "utf8" });
console.log(result.stderr); // => Error message\n

API

runsync.spawn(executable, [args], [options])

var res = runsync.spawn("node", ["-e", "console.log('Hello, World!')"], { encoding: "utf8" });
console.log(res.stdout) // => 'Hello, World!\n'

runsync.exec(command, [options])

var output = runsync.exec("sleep 3 && echo Hello!", { timeout: 1000 });
// => throw Exception because of timeout

runsync.execFile(command, [options])

var html = runsync.execFile("curl", ["--silent", "-X", "GET", "http://example.com"]);
console.log(html.toString()); // => '<!doctype html>\n<html>\n<head>\n ...'

runsync.popen(command, [options])

  • This is similar to runsync.exec, but it returns spawn object likes runsync.spawn.
  • This method will not throw Exceptions even if command fails.
var result = runsync.popen("echo `cat` && echo strerr 1>&2", { input: "stdin", encoding: "utf8" });
console.log(result.stdout) // => "stdin\n"
console.log(result.stderr) // => "stderr\n"

runsync.shell(command, [options])

  • This is similar to runsync.exec, but always set 'inherit' to options.stdio.
  • Returns Nothing(undefined).
  • This method will throw Exceptions if command fails.
try {
  runsync.shell("mocha --reporter nyan");
  // 31  -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_,------,
  // 1   -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_|   /\_/\ 
  // 0   -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-^|__( x .x) 
  //     -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-  ""  "" 
  //  31 passing (468ms)
  //  1 failing

} catch(err) {
  console.log(err.message);
  // => 'Command failed: `mocha -u tdd --reporter nyan`'
}

runsync's People

Contributors

norahiko avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

ljharb

runsync's Issues

runsync throws error when sed pattern contains carriage returns

sed -i 's/\r/\n/g' /path/to/some/file

This shell command works in bash terminal, when i run via runsync, it throws error.

runsync command,

var sedArgs = [
  "-i",
  "'s/\r/\n/g'",
  path.join(theFolder, "finalreport.html")
]
````.

It looks like, when there are escape characters - \r, \n in the sed pattern, it throws error.
When i give a simpler pattern like, `s/abc/def/g`, it works without any complaints.

Crashes in node 0.11

in node 0.11.14, I get the following error:

module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: Module did not self-register.
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (./node_modules/runsync/index.js:32:15)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

It looks like this polyfill isn't actually checking for the existence of execFileSync etc on child_process .

Doesn't install on node 0.8

See https://travis-ci.org/ljharb/es7-shim/jobs/46043274 for failure output.

var tmpdir = require("os").tmpdir();
                           ^
TypeError: Object #<Object> has no method 'tmpdir'
    at Object.<anonymous> (/home/travis/build/ljharb/es7-shim/node_modules/runsync/index.js:11:28)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/home/travis/build/ljharb/es7-shim/test/util/runner.js:1:74)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)

It'd be ideal if this module could be used on as many versions of node as possible. Is there any way that could happen, at least for node 0.8?

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.